<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Erxin, Shang(Edwin, 尚尔鑫)&#039;s Home Page &#187; Python</title>
	<atom:link href="http://www.shangerxin.com/?feed=rss2&#038;tag=python" rel="self" type="application/rss+xml" />
	<link>http://www.shangerxin.com</link>
	<description>Knowledge should be free.</description>
	<lastBuildDate>Tue, 24 Aug 2021 02:27:23 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.8.13</generator>
	<item>
		<title>Memory increasing issue when convert Pillow Image (8.3.1) either to Numpy array or OpenCV Image</title>
		<link>http://www.shangerxin.com/?p=424</link>
		<comments>http://www.shangerxin.com/?p=424#comments</comments>
		<pubDate>Wed, 11 Aug 2021 06:29:05 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Machine Learning]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=424</guid>
		<description><![CDATA[Background introduction Recently our project encounter a memory increase issue after upgrade from Pillow 8.2.0 to Pillow 8.3.0. Memory consumption after upgrading the Pillow (8.3.1): The memory consumption before upgrading the Pillow (8.2.0): It seems the library bring lots of memory increments. BTW. The issue can not be produce before we build the project. Solution After [&#8230;]]]></description>
				<content:encoded><![CDATA[<h1>Background introduction</h1>
<p>Recently our project encounter a memory increase issue after upgrade from <a href="https://python-pillow.org/">Pillow</a> 8.2.0 to Pillow 8.3.0.</p>
<p>Memory consumption after upgrading the Pillow (8.3.1):</p>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/issue.png"><img class="aligncenter  wp-image-425" alt="issue" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/issue.png" width="1123" height="583" /></a></p>
<p>The memory consumption before upgrading the Pillow (8.2.0):</p>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/normal.png"><img class="aligncenter size-full wp-image-426" alt="normal" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/normal.png" width="985" height="392" /></a></p>
<p>It seems the library bring lots of memory increments. BTW. The issue can not be produce before we build the project.</p>
<h1>Solution</h1>
<p>After I spent a few days to find the root cause and the solution. The issue code is located to a pillow image conversion</p>
<p>At the beginning, I suspect this would be a regression in Pillow, so I search their github issues</p>
<p><a href="https://github.com/python-pillow/Pillow/issues/2019">https://github.com/python-pillow/Pillow/issues/2019</a></p>
<p><a href="https://github.com/python-pillow/Pillow/issues/5180">https://github.com/python-pillow/Pillow/issues/5180</a></p>
<p>Both of these two threads indicate the issues are fixed. But I still tried to pull the fix code into our project. Without luck.</p>
<p>To keep the long story short, I grab two heap memory dump and compare with objects which increased most. This great help me reduce the search scope.</p>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/stack-trace.png"><img class="aligncenter size-full wp-image-439" alt="stack-trace" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/stack-trace.png" width="680" height="948" /></a></p>
<p>The relative issue code:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="python" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">np.<span style="color: #dc143c;">array</span><span style="color: black;">&#40;</span>pillow_image, <span style="color: black;">[</span>dtype=...<span style="color: black;">]</span><span style="color: black;">&#41;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">np.<span style="color: black;">asarray</span><span style="color: black;">&#40;</span>pillow_image<span style="color: black;">&#41;</span></div></li></ol></pre></div></div>
<p>&nbsp;</p>
<p>All the above conversion will lead to the numpy array keep exist till a certain point trigger python release the accumulated objects.</p>
<p>Then I check the release note of the Pillow, there is only one place directly relative to numpy array. First I try to withdraw the changes directly in 8.3.1, no help. Second try to directly down grade to 8.3.0. Still not works.</p>
<p>Now, what? Checked Pillow API, Numpy API, OpenCV API again and also check their source. A idea pop up and write a workaround code</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="python" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">numpy_array = np.<span style="color: black;">frombuffer</span><span style="color: black;">&#40;</span>pillow_image.<span style="color: black;">tobytes</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, dtype=np.<span style="color: black;">uint8</span><span style="color: black;">&#41;</span></div></li></ol></pre></div></div>
<p>To convert the image array to OpenCV</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.shangerxin.com/wordpress/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="python" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808080; font-style: italic;"># 3 or 4 base on your image mode is RGB or RGBA</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">numpy_array.<span style="color: black;">shape</span> = <span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #008000;">reversed</span><span style="color: black;">&#40;</span>image.<span style="color: black;">size</span><span style="color: black;">&#41;</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span> </div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">&nbsp;</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808080; font-style: italic;"># If want to convert the image to BGR then call the OpenCV method</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #808080; font-style: italic;"># COLOR_RGB2BGR will required the image mode is 3</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">numpy_array= cv2.<span style="color: black;">cvtColor</span><span style="color: black;">&#40;</span>numpy_array, cv2.<span style="color: black;">COLOR_RGB2BGR</span><span style="color: black;">&#41;</span></div></li></ol></pre></div></div>
<p>It works! Now the memory consumption return to normal level.</p>
<h1><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/fixed.png"><img class="aligncenter size-full wp-image-427" alt="fixed" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2021/08/fixed.png" width="1034" height="536" /></a></h1>
<p>There are several places directly use the image conversion, we should consider unify the similar logic into a utility class and add a wrapper for the third party library the isolation the influences.</p>
<h1>Summary</h1>
<p>Third party library upgrade is a risk to a product. We have to upgrade the library due to a security reason in this time. The Pillow changes are checked too, have found several suspicious code will cause the issue. Need time to test, maybe update the result later.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=424</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips for resolve pip install error for some of the python 2.7 package on window</title>
		<link>http://www.shangerxin.com/?p=343</link>
		<comments>http://www.shangerxin.com/?p=343#comments</comments>
		<pubDate>Thu, 21 Dec 2017 01:27:48 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=343</guid>
		<description><![CDATA[Pip is a wide used python package management tool, it works properly most of the time. But occasionally there will be a few error when install some special package which may required local build after download. Here are two common ways to resolve these kinds of error 1. Use a prebuild binary, the most common [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Pip is a wide used python package management tool, it works properly most of the time. But occasionally there will be a few error when install some special package which may required local build after download.<br />
Here are two common ways to resolve these kinds of error </p>
<p>1. Use a prebuild binary, the most common library could be download from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs">here</a>. But the links seems dead for a while.</p>
<p>2. Install the necessary Cpp compiler for python 2.7 on window from <a href="https://www.microsoft.com/en-us/download/details.aspx?id=44266">here</a></p>
<p>After install the compiler rerun the pip install
<package> again</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=343</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic Export About:Config Content Compare the Difference between for Firefox</title>
		<link>http://www.shangerxin.com/?p=262</link>
		<comments>http://www.shangerxin.com/?p=262#comments</comments>
		<pubDate>Wed, 02 Dec 2015 03:24:07 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Autoit]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=262</guid>
		<description><![CDATA[Requirement: We need to compare the difference between the configuration changes between the new vision of the FF and the previous version We wish to compare the configuration setting in plain text. Then we could use the compare tools such as beyond compare or winmerge to give us a quick visual for the difference. The [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><strong>Requirement:</strong></p>
<p>We need to compare the difference between the configuration changes between the new vision of the FF and the previous version</p>
<p>We wish to compare the configuration setting in plain text. Then we could use the compare tools such as beyond compare or winmerge to give us a quick visual for the difference.</p>
<p><strong>The Problem:</strong></p>
<p>There is not a official way to export the <a href="http://aboutconfg">about:confg</a> page from FF into plain text file. There is a <a href="http://kb.mozillazine.org/Prefs.js_file">prefs.js</a> file locate in the firefox profile folder, it contains some of the configuration setting but not all.</p>
<p><strong>Known solutions to export the about:config but not well enough:</strong></p>
<ul>
<li>User prefs.js for only export the custom settings, check the link(<a href="http://superuser.com/questions/165164/how-to-export-firefox-aboutconfig-into-plain-text-file">http://superuser.com/questions/165164/how-to-export-firefox-aboutconfig-into-plain-text-file</a>). But it is not fit for our requirement.</li>
<li>User python to analyze the entire profile folder and parse the preference relative *.js files. But it is not sure works for the new versions of the FF(<a href="http://stackoverflow.com/questions/24548306/how-to-read-firefoxs-aboutconfig-entries-using-python">http://stackoverflow.com/questions/24548306/how-to-read-firefoxs-aboutconfig-entries-using-python</a>)</li>
</ul>
<p><strong>Solution for export the about:config</strong>:</p>
<p>Use the GUI automation tool(<a href="https://www.autoitscript.com/site/autoit/">autoit</a>) to help export the configuration directly from the <a href="http://aboutconfig">about:config</a> page. The script is export-opened-firefox-config.au3 which could be download from <a href="https://github.com/shangerxin/PersontalTools/">my github repot</a></p>
<ol>
<li>Install <a href="https://www.autoitscript.com/site/autoit/">autoit</a>, which double be download from official website follow the previous link</li>
<li>Download the export-opened-firefox-config.au3</li>
<li>Before run the script close all the Firefox process existed in the current system</li>
<li>Run the script export-opened-firefox-config.au3</li>
<li>Open the Firefox that you want to export the about the configure content</li>
<li>The script will start automatically and wait for it stops, please make any user input during the script execution</li>
<li>The output.txt will be generated at the same location of the script file export-opened-firefox-config.au3 which contain all the configuration values</li>
<li>Check the last line of the output.txt contain the last item of the about:config. If the values are same then all is well. If not please modify the sleep time for the script to give more calculate time for the low performance system.</li>
</ol>
<p><strong>Solution for generate the difference compilation results:</strong></p>
<p>Use <a href="https://www.python.org/">python</a> to parse and generate the previous generate configuration files and the current user.js settings which contain in the LR-INSTALL-DIRECTORY\dat\FFProfile\user.js. The python script could be check out from my personal tools <a href="https://github.com/shangerxin/PersontalTools/">repo from github</a></p>
<ol>
<li>Install python 2.7.x, if current system doesn&#8217;t contain python environment</li>
<li>Install <a href="http://www.python-excel.org/">xlsxwriter</a> from pip or download the package install manually. Check this <a href="https://docs.python.org/2/install/index.html">link</a>, if you doesn&#8217;t familiar with python</li>
<li>Download the script</li>
<li>Copy and replace the about config content files and the user.js into the data folder to make it follow this file structure</li>
</ol>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_110835.png"><img alt="2015-12-02_110835" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_110835-300x104.png" width="300" height="104" /></a></p>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_111617.png"><img alt="2015-12-02_111617" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_111617-300x196.png" width="300" height="196" /></a></p>
<p>5. Execute the python script the output files will be overwrite and generated automatically  Note: If the excel file is not required you could common the script lines relative to generate excel to only generate plain text report. The key/value pair is separate by semicolons like this:</p>
<p><a href="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_111832.png"><img alt="2015-12-02_111832" src="http://www.shangerxin.com/wordpress/wp-content/uploads/2015/12/2015-12-02_111832-300x157.png" width="300" height="157" /></a></p>
<p><strong>References</strong></p>
<ul>
<li>A addon for add description information for the <a href="http://aboutconfig">about:config</a> page <a href="https://addons.mozilla.org/en-US/firefox/addon/config-descriptions/">https://addons.mozilla.org/en-US/firefox/addon/config-descriptions/</a></li>
<li>The wiki page for the <a href="http://aboutconfig">about:config</a>, <a href="http://kb.mozillazine.org/About:config_entries">http://kb.mozillazine.org/About:config_entries</a></li>
<li>Some of the preference documents for the <a href="http://aboutconfig">about:config</a>, <a href="http://kb.mozillazine.org/Category:Preferences">http://kb.mozillazine.org/Category:Preferences</a></li>
<li>Document for user.js, <a href="http://kb.mozillazine.org/User.js">http://kb.mozillazine.org/User.js</a></li>
</ul>
<p>Note: the content of the wiki may adapt to the old version of FF to check the new version please follow the link supplied in the wiki pages.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=262</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Python to Create a Tree View Command Line Tool</title>
		<link>http://www.shangerxin.com/?p=258</link>
		<comments>http://www.shangerxin.com/?p=258#comments</comments>
		<pubDate>Thu, 12 Nov 2015 13:34:22 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=258</guid>
		<description><![CDATA[In recent days I need to generate a directory free from the window command prompt. As I known there is a DOS tool called tree could do this. But it is not quite fit for my requirement. Here is an example which the graphic generated by built-in tree command in window. D:\PersonalTools&#62;tree D:\emacs-24.5 /A 卷 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In recent days I need to generate a directory free from the window command prompt. As I known there is a DOS tool called tree could do this. But it is not quite fit for my requirement. Here is an example which the graphic generated by built-in tree command in window.</p>
<blockquote><p>D:\PersonalTools&gt;tree D:\emacs-24.5 /A<br />
卷 WareHouse 的文件夹 PATH 列表<br />
卷序列号为 64CA-A0C3</p>
<p>D:\EMACS-24.5<br />
+&#8212;admin<br />
|   +&#8212;charsets<br />
|   |   \&#8212;mapfiles<br />
|   +&#8212;coccinelle<br />
|   +&#8212;grammars<br />
|   +&#8212;notes<br />
|   +&#8212;nt<br />
|   \&#8212;unidata<br />
+&#8212;build-aux<br />
|   \&#8212;snippet<br />
+&#8212;doc<br />
|   +&#8212;emacs<br />
|   +&#8212;lispintro<br />
|   +&#8212;lispref<br />
|   +&#8212;man<br />
|   \&#8212;misc<br />
+&#8212;etc<br />
|   +&#8212;charsets<br />
|   +&#8212;e<br />
|   +&#8212;forms<br />
|   +&#8212;gnus<br />
|   +&#8212;images<br />
|   |   +&#8212;custom<br />
|   |   +&#8212;ezimage<br />
|   |   +&#8212;gnus<br />
|   |   +&#8212;gud<br />
|   |   +&#8212;icons<br />
|   |   |   +&#8212;allout-widgets<br />
|   |   |   |   +&#8212;dark-bg<br />
|   |   |   |   \&#8212;light-bg<br />
|   |   |   \&#8212;hicolor<br />
|   |   |       +&#8212;128&#215;128<br />
|   |   |       |   \&#8212;apps<br />
|   |   |       +&#8212;16&#215;16<br />
|   |   |       |   \&#8212;apps<br />
|   |   |       +&#8212;24&#215;24<br />
|   |   |       |   \&#8212;apps<br />
|   |   |       +&#8212;32&#215;32<br />
|   |   |       |   \&#8212;apps<br />
|   |   |       +&#8212;48&#215;48<br />
|   |   |       |   \&#8212;apps<br />
|   |   |       \&#8212;scalable<br />
|   |   |           +&#8212;apps<br />
|   |   |           \&#8212;mimetypes<br />
|   |   +&#8212;low-color<br />
|   |   +&#8212;mail<br />
|   |   +&#8212;mpc<br />
|   |   +&#8212;newsticker<br />
|   |   +&#8212;smilies<br />
|   |   |   +&#8212;grayscale<br />
|   |   |   \&#8212;medium<br />
|   |   \&#8212;tree-widget<br />
|   |       +&#8212;default<br />
|   |       \&#8212;folder<br />
|   +&#8212;nxml<br />
|   +&#8212;org<br />
|   +&#8212;refcards<br />
|   +&#8212;schema<br />
|   +&#8212;srecode<br />
|   +&#8212;themes<br />
|   \&#8212;tutorials<br />
+&#8212;info<br />
+&#8212;leim<br />
|   +&#8212;CXTERM-DIC<br />
|   +&#8212;MISC-DIC<br />
|   \&#8212;SKK-DIC<br />
+&#8212;lib<br />
+&#8212;lib-src<br />
+&#8212;lisp<br />
|   +&#8212;calc<br />
|   +&#8212;calendar<br />
|   +&#8212;cedet<br />
|   |   +&#8212;ede<br />
|   |   +&#8212;semantic<br />
|   |   |   +&#8212;analyze<br />
|   |   |   +&#8212;bovine<br />
|   |   |   +&#8212;decorate<br />
|   |   |   +&#8212;symref<br />
|   |   |   \&#8212;wisent<br />
|   |   \&#8212;srecode<br />
|   +&#8212;emacs-lisp<br />
|   +&#8212;emacs-parallel<br />
|   +&#8212;emulation<br />
|   +&#8212;erc<br />
|   +&#8212;eshell<br />
|   +&#8212;gnus<br />
|   +&#8212;international<br />
|   +&#8212;language<br />
|   +&#8212;leim<br />
|   |   +&#8212;ja-dic<br />
|   |   \&#8212;quail<br />
|   +&#8212;mail<br />
|   +&#8212;mh-e<br />
|   +&#8212;net<br />
|   +&#8212;nxml<br />
|   +&#8212;obsolete<br />
|   +&#8212;org<br />
|   +&#8212;play<br />
|   +&#8212;progmodes<br />
|   +&#8212;term<br />
|   +&#8212;textmodes<br />
|   +&#8212;url<br />
|   \&#8212;vc<br />
+&#8212;lwlib<br />
+&#8212;m4<br />
+&#8212;msdos<br />
+&#8212;nextstep<br />
|   +&#8212;Cocoa<br />
|   |   \&#8212;Emacs.base<br />
|   |       \&#8212;Contents<br />
|   |           \&#8212;Resources<br />
|   +&#8212;GNUstep<br />
|   |   \&#8212;Emacs.base<br />
|   |       \&#8212;Resources<br />
|   \&#8212;templates<br />
+&#8212;nt<br />
|   +&#8212;icons<br />
|   \&#8212;inc<br />
|       +&#8212;arpa<br />
|       +&#8212;netinet<br />
|       \&#8212;sys<br />
+&#8212;oldXMenu<br />
+&#8212;site-lisp<br />
\&#8212;src<br />
\&#8212;bitmaps</p></blockquote>
<p>A quite complicate file structure for emacs 24.5. There are several limitations for this command.</p>
<ol>
<li>It can&#8217;t control the iteration depth</li>
<li>When display with files it doesn&#8217;t generated the dash lines which is not clearly to indicate the file structure</li>
<li>If we could give a depth parameter I also want to display the sub items as ellipsis to indicate there is something under but which is omitted</li>
</ol>
<p>So I use python to write a custom version to enhance this command called <a href="https://github.com/shangerxin/PersontalTools">treex</a>. It support generated the same structure as the tree command but also provide additional control switch. The source code is already pushed to my personal repository in GitHub. Feel free to check it out.</p>
<p>The help information is</p>
<blockquote><p>usage: treex.py [-h] [-f] [-d DEPTH] [-m] [-e] path</p>
<p>A Cmd Line Tool for Graphically displays the folder structure of a drive or<br />
path</p>
<p>positional arguments:<br />
path</p>
<p>optional arguments:<br />
-h, &#8211;help            show this help message and exit<br />
-f, &#8211;file            Display the names of the files in each folder<br />
-d DEPTH, &#8211;depth DEPTH<br />
Display the depth number<br />
-m, &#8211;mark            Mark the item is file or directory<br />
-e, &#8211;ellipsis        Mark the next sub-item with ellipsis</p>
<p>Create by Edwin, Shang(Shang, Erxin) License under MIT. Version 1.0.0</p></blockquote>
<p>Try to use the treex to generate a depth 2 directory structure</p>
<blockquote><p>D:\PersonalTools&gt;c:\Python27\python.exe treex.py D:\emacs-24.5 -d 2<br />
Folder path listing<br />
D:\emacs-24.5<br />
+&#8212;admin<br />
|   +&#8212;charsets<br />
|   +&#8212;coccinelle<br />
|   +&#8212;grammars<br />
|   +&#8212;notes<br />
|   +&#8212;nt<br />
|   \&#8212;unidata<br />
+&#8212;build-aux<br />
|   \&#8212;snippet<br />
+&#8212;doc<br />
|   +&#8212;emacs<br />
|   +&#8212;lispintro<br />
|   +&#8212;lispref<br />
|   +&#8212;man<br />
|   \&#8212;misc<br />
+&#8212;etc<br />
|   +&#8212;charsets<br />
|   +&#8212;e<br />
|   +&#8212;forms<br />
|   +&#8212;gnus<br />
|   +&#8212;images<br />
|   +&#8212;nxml<br />
|   +&#8212;org<br />
|   +&#8212;refcards<br />
|   +&#8212;schema<br />
|   +&#8212;srecode<br />
|   +&#8212;themes<br />
|   \&#8212;tutorials<br />
+&#8212;info<br />
+&#8212;leim<br />
|   +&#8212;CXTERM-DIC<br />
|   +&#8212;MISC-DIC<br />
|   \&#8212;SKK-DIC<br />
+&#8212;lib<br />
+&#8212;lib-src<br />
+&#8212;lisp<br />
|   +&#8212;calc<br />
|   +&#8212;calendar<br />
|   +&#8212;cedet<br />
|   +&#8212;emacs-lisp<br />
|   +&#8212;emacs-parallel<br />
|   +&#8212;emulation<br />
|   +&#8212;erc<br />
|   +&#8212;eshell<br />
|   +&#8212;gnus<br />
|   +&#8212;international<br />
|   +&#8212;language<br />
|   +&#8212;leim<br />
|   +&#8212;mail<br />
|   +&#8212;mh-e<br />
|   +&#8212;net<br />
|   +&#8212;nxml<br />
|   +&#8212;obsolete<br />
|   +&#8212;org<br />
|   +&#8212;play<br />
|   +&#8212;progmodes<br />
|   +&#8212;term<br />
|   +&#8212;textmodes<br />
|   +&#8212;url<br />
|   \&#8212;vc<br />
+&#8212;lwlib<br />
+&#8212;m4<br />
+&#8212;msdos<br />
+&#8212;nextstep<br />
|   +&#8212;Cocoa<br />
|   +&#8212;GNUstep<br />
|   \&#8212;templates<br />
+&#8212;nt<br />
|   +&#8212;icons<br />
|   \&#8212;inc<br />
+&#8212;oldXMenu<br />
+&#8212;site-lisp<br />
\&#8212;src<br />
\&#8212;bitmaps</p></blockquote>
<p>Here is another result for generate with ellipsis and marks</p>
<blockquote><p>D:\PersonalTools&gt;c:\Python27\python.exe treex.py D:\emacs-24.5 -d 2 -e -m<br />
Folder path listing<br />
D:\emacs-24.5<br />
[d]+&#8212;admin<br />
[d]|   +&#8212;charsets<br />
[d]|   |   \&#8212;&#8230;<br />
[d]|   +&#8212;coccinelle<br />
[d]|   +&#8212;grammars<br />
[d]|   +&#8212;notes<br />
[d]|   +&#8212;nt<br />
[d]|   \&#8212;unidata<br />
[d]+&#8212;build-aux<br />
[d]|   \&#8212;snippet<br />
[d]+&#8212;doc<br />
[d]|   +&#8212;emacs<br />
[d]|   +&#8212;lispintro<br />
[d]|   +&#8212;lispref<br />
[d]|   +&#8212;man<br />
[d]|   \&#8212;misc<br />
[d]+&#8212;etc<br />
[d]|   +&#8212;charsets<br />
[d]|   +&#8212;e<br />
[d]|   +&#8212;forms<br />
[d]|   +&#8212;gnus<br />
[d]|   +&#8212;images<br />
[d]|   |   +&#8212;&#8230;<br />
[d]|   +&#8212;nxml<br />
[d]|   +&#8212;org<br />
[d]|   +&#8212;refcards<br />
[d]|   +&#8212;schema<br />
[d]|   +&#8212;srecode<br />
[d]|   +&#8212;themes<br />
[d]|   \&#8212;tutorials<br />
[d]+&#8212;info<br />
[d]+&#8212;leim<br />
[d]|   +&#8212;CXTERM-DIC<br />
[d]|   +&#8212;MISC-DIC<br />
[d]|   \&#8212;SKK-DIC<br />
[d]+&#8212;lib<br />
[d]+&#8212;lib-src<br />
[d]+&#8212;lisp<br />
[d]|   +&#8212;calc<br />
[d]|   +&#8212;calendar<br />
[d]|   +&#8212;cedet<br />
[d]|   |   +&#8212;&#8230;<br />
[d]|   +&#8212;emacs-lisp<br />
[d]|   +&#8212;emacs-parallel<br />
[d]|   +&#8212;emulation<br />
[d]|   +&#8212;erc<br />
[d]|   +&#8212;eshell<br />
[d]|   +&#8212;gnus<br />
[d]|   +&#8212;international<br />
[d]|   +&#8212;language<br />
[d]|   +&#8212;leim<br />
[d]|   |   +&#8212;&#8230;<br />
[d]|   +&#8212;mail<br />
[d]|   +&#8212;mh-e<br />
[d]|   +&#8212;net<br />
[d]|   +&#8212;nxml<br />
[d]|   +&#8212;obsolete<br />
[d]|   +&#8212;org<br />
[d]|   +&#8212;play<br />
[d]|   +&#8212;progmodes<br />
[d]|   +&#8212;term<br />
[d]|   +&#8212;textmodes<br />
[d]|   +&#8212;url<br />
[d]|   \&#8212;vc<br />
[d]+&#8212;lwlib<br />
[d]+&#8212;m4<br />
[d]+&#8212;msdos<br />
[d]+&#8212;nextstep<br />
[d]|   +&#8212;Cocoa<br />
[d]|   |   \&#8212;&#8230;<br />
[d]|   +&#8212;GNUstep<br />
[d]|   |   \&#8212;&#8230;<br />
[d]|   \&#8212;templates<br />
[d]+&#8212;nt<br />
[d]|   +&#8212;icons<br />
[d]|   \&#8212;inc<br />
[d]|       +&#8212;&#8230;<br />
[d]+&#8212;oldXMenu<br />
[d]+&#8212;site-lisp<br />
[d]\&#8212;src<br />
[d]    \&#8212;bitmaps</p></blockquote>
<p>The key technical point is the depth first traversal algorithms, and I implement it with nonrecursive mode to reduce the stack usage.</p>
<p>The other key point is how to generate the graphic. There is a pattern between the second line and the previous line. So I use it. The implementation could be found from the source.</p>
<p>That&#8217;s all. Happy coding.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=258</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python基础教程， 第二章 基本数据类型与语法， Basic data types and syntax</title>
		<link>http://www.shangerxin.com/?p=108</link>
		<comments>http://www.shangerxin.com/?p=108#comments</comments>
		<pubDate>Tue, 06 Jan 2015 01:23:43 +0000</pubDate>
		<dc:creator><![CDATA[Shang Erxin]]></dc:creator>
				<category><![CDATA[Video Training]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shangerxin.com/?p=108</guid>
		<description><![CDATA[本章主要介绍了Python的基本数据类型以及基本语法，并介绍了一些python风格的类型操作的写法 基本数据类型 基本操作类型 变量的定义 基本程序流程控制类型 Python风格的写法]]></description>
				<content:encoded><![CDATA[<p>本章主要介绍了Python的基本数据类型以及基本语法，并介绍了一些python风格的类型操作的写法</p>
<li>基本数据类型</li>
<li>基本操作类型</li>
<li>变量的定义</li>
<li>基本程序流程控制类型</li>
<li>Python风格的写法</li>
<p><embed src="http://player.youku.com/player.php/sid/XODY1NDIxNzQw/v.swf" allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shangerxin.com/?feed=rss2&#038;p=108</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
