<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<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/"
	>

<channel>
	<title>Dryice Liu's Blog &#187; python</title>
	<link>http://dryice.name/blog</link>
	<description></description>
	<pubDate>Tue, 31 Aug 2010 12:01:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>Copy file in the order of their name</title>
		<link>http://dryice.name/blog/freebsd/copy-file-in-the-order-of-their-name/</link>
		<comments>http://dryice.name/blog/freebsd/copy-file-in-the-order-of-their-name/#comments</comments>
		<pubDate>Wed, 30 Jan 2008 10:11:57 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<category><![CDATA[misc]]></category>

		<category><![CDATA[freebsd]]></category>
<category>copy</category><category>cross platform</category><category>ipod</category><category>mp3</category><category>order</category><category>python</category>
		<guid isPermaLink="false">http://dryice.name/blog/freebsd/copy-file-in-the-order-of-their-name/</guid>
		<description><![CDATA[Last weekend I got myself a small MP3 player called Q12. 
I really like this small one cause I can carry it everywhere and save me some time while I&#8217;m walking or waiting.
It support file/folder visiting of the files, and not support MP3 tag and organized with artiste, album, etc like Apple IPod. This is [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I got myself a small MP3 player called Q12. <img src="http://img2.zol.com.cn/product/14_450x337/391/ceg3c2zMZkig.jpg" title="Q12" alt="Q12" height="375" width="253" /></p>
<p>I really like this small one cause I can carry it everywhere and save me some time while I&#8217;m walking or waiting.</p>
<p>It support file/folder visiting of the files, and not support MP3 tag and organized with artiste, album, etc like Apple IPod. This is the reason I prefer it over the <a href="http://www.sandisk.com/Products/Default.aspx?CatID=1363" target="_blank">Sandisk Clip.</a> Because most of the time I&#8217;ll use it to listen podcasts or audio books.</p>
<p>However there is a problem: It won&#8217;t sort the files. I just can&#8217;t find any options to sort the files in the menu system or the user user manual. Then I thought it might sort the files by their access time, or create time, so I wrote <a href="http://dryice.name/blog/wp-content/uploads/2008/01/mp3reorgpy.gz" title="mp3 reorg">mp3 reorg</a> , which will change the atime/ctime of all the files so the fils should appear earlier will get an earlier atime/ctime. However it turns out this little mp3 don&#8217;t obey that too, they just read the FAT table and don&#8217;t do any sort! Finially I have to wrote another one, <a href="http://dryice.name/blog/wp-content/uploads/2008/01/mp3copypy.gz" title="mp3 copy">mp3 copy</a>, to copy the files in the order I want.</p>
<p>Just put them here in case anyone could find them useful. Note &#8220;create time&#8221; is a dos/windows only thing, we don&#8217;t have this on (most) Unix systems. If your mp3 use atime (access time) or ctime (changed time), you could use the &#8220;mp3reorg&#8221; script on Unix platform too, just comment out the lines with &#8220;win32&#8243; in it. The &#8220;mp3 copy&#8221; script works cross platform, though.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=863&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_863" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/freebsd/copy-file-in-the-order-of-their-name/feed/</wfw:commentRss>
		</item>
		<item>
		<title>pylons</title>
		<link>http://dryice.name/blog/python/turbogears/pylons/</link>
		<comments>http://dryice.name/blog/python/turbogears/pylons/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 14:36:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[turbogears]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/pylons/</guid>
		<description><![CDATA[I gave Pylons a try today, followed the turorials, read some
documents, and compared it with my current Python web frame work of
choice: TurboGears.
Though many people say good words for pylons, I believe TurboGears is
still a good choice for me at this time:

TG is one year older than Pylons, which means more stable most of
the time
TG [...]]]></description>
			<content:encoded><![CDATA[<p>I gave <a href="http://pylonshq.com/">Pylons</a> a try today, followed the turorials, read some<br />
documents, and compared it with my current Python web frame work of<br />
choice: <a href="http://www.turbogears.org/">TurboGears</a>.</p>
<p>Though many people <a href="http://blog.ianbicking.org/turbogears-and-pylons.html">say good words for pylons</a>, I believe TurboGears is<br />
still a good choice for me at this time:</p>
<ul>
<li>TG is one year older than Pylons, which means more stable most of<br />
the time</li>
<li>TG comes with more tools that is handy. Say for<br />
internationalization, TG is much easier. It can handle strings in<br />
both the Python files and template. It also do the language choose<br />
automatically.</li>
<li>The major difference between the two is the dispatching<br />
mechanisms. Though Pylons&#8217; URL matching is more flexable, I found<br />
the TurboGears tree like structure quite nature, as some one from<br />
<a href="http://www.mems-exchange.org/software/quixote/">Quixote</a>.</li>
<li>TurboGears comes with AJAX support</li>
<li>TurboGears comes with a good widget library, and many more in the<br />
<a href="http://www.mems-exchange.org/software/quixote/">cogbin</a>. <a href="http://toscawidgets.org/">ToscoWidgets</a>, which is seperated from TurboGears, will be<br />
used in the future release of both. And for sure it will be much<br />
easier to switch to ToscoWidgets from TG than from Pylons.</li>
<li>One thing TG lakes is the caching. However when it comes in a<br />
future release, I can benefit from it with little or no change of<br />
my application code.</li>
<li>TG returns a dict/JSON from the controller. This seperates the view<br />
and controller, and makes multiple views (say HTML and RSS feed)<br />
quite easier. While the &#8220;c&#8221; global accross controller and templage<br />
is, well, rather urgly from my point of view.</li>
</ul>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=631&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_631" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/turbogears/pylons/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic handling of &#8216;virtual file names&#8217;, or URL paths with file extensions</title>
		<link>http://dryice.name/blog/python/turbogears/dynamic-handling-of-virtual-file-names-or-url-paths-with-file-extensions/</link>
		<comments>http://dryice.name/blog/python/turbogears/dynamic-handling-of-virtual-file-names-or-url-paths-with-file-extensions/#comments</comments>
		<pubDate>Fri, 13 Apr 2007 10:39:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[turbogears]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/dynamic-handling-of-virtual-file-names-or-url-paths-with-file-extensions/</guid>
		<description><![CDATA[Well TurboGears  uses CherryPY as the URL dispatcher. And by default
it uses the object structure as a tree like structure for the URL
paths, like the file system structure.
This works fine most of the time. However, the Python function name is
quite restrict than what we can use in an URL. For example, the &#8220;.&#8221;
character is [...]]]></description>
			<content:encoded><![CDATA[<p>Well <a href="http://www.turbogears.org/">TurboGears</a>  uses <a href="http://www.cherrypy.org/">CherryPY</a> as the URL dispatcher. And by default<br />
it uses the object structure as a tree like structure for the URL<br />
paths, like the file system structure.</p>
<p>This works fine most of the time. However, the Python function name is<br />
quite restrict than what we can use in an URL. For example, the &#8220;.&#8221;<br />
character is not allowed. So, for example, if I want to make the URL<br />
looks the old traditional way, like &#8220;/index.html&#8221;. I&#8217;ll need to write<br />
a BIG elif clause in the default() function.</p>
<p>The good news is that after some digg on Google I found<br />
<a href="http://www.cherrypy.org/ticket/87">This CherryPY ticket</a>. And the solution is simple: I could use<br />
index_html as the function name, and when user types index.html in the<br />
URL, CherryPY will find index_html <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=632&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_632" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/turbogears/dynamic-handling-of-virtual-file-names-or-url-paths-with-file-extensions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bicyclerepair man: a refactoring code browser</title>
		<link>http://dryice.name/blog/python/bicyclerepair-man-a-refactoring-code-browser/</link>
		<comments>http://dryice.name/blog/python/bicyclerepair-man-a-refactoring-code-browser/#comments</comments>
		<pubDate>Mon, 05 Mar 2007 07:10:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/bicyclerepair-man-a-refactoring-code-browser/</guid>
		<description><![CDATA[On my way of finding a tool to easy find defination/reference of Python code, I found Bicyclerepair man. First I just use it to find definatins and references. And after some hacking, it works pretty good with my Emacs.
After reading some document, I find it opens a BIG door: it&#8217;s a tool to help me [...]]]></description>
			<content:encoded><![CDATA[<p>On my way of finding a tool to easy find defination/reference of Python code, I found <a href="http://bicyclerepair.sourceforge.net/">Bicyclerepair man</a>. First I just use it to find definatins and references. And after some hacking, it works pretty good with my Emacs.</p>
<p>After reading some document, I find it opens a BIG door: it&#8217;s a tool to help me refactoring my code. That is, make my codes more structure, smaller, and easy to read.</p>
<p>Some features are, make part of a function to be a seperate function, part of an expression to be a seperate expression, move classes among modules.</p>
<p>I haven&#8217;t use these features but I&#8217;ve already love it <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=636&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_636" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/bicyclerepair-man-a-refactoring-code-browser/feed/</wfw:commentRss>
		</item>
		<item>
		<title>quixote is not ready for python 2.5</title>
		<link>http://dryice.name/blog/python/quixote/quixote-is-not-ready-for-python-25/</link>
		<comments>http://dryice.name/blog/python/quixote/quixote-is-not-ready-for-python-25/#comments</comments>
		<pubDate>Wed, 11 Oct 2006 07:04:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[quixote]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/quixote-is-not-ready-for-python-25/</guid>
		<description><![CDATA[I tried to upgrade to Python 2.5 today, however, some of the packages I use daily is not ready, including quixote.
At least on change in compile.ast.From makes quixote 2.4 not working in Python 2.5.
I think I&#8217;ll stick with Python 2.4 till more packages come to work with 2.5.

Share This
]]></description>
			<content:encoded><![CDATA[<p>I tried to upgrade to <a href="http://www.python.org">Python</a> 2.5 today, however, some of the packages I use daily is not ready, including quixote.</p>
<p>At least on change in compile.ast.From makes quixote 2.4 not working in <a href="http://www.python.org">Python</a> 2.5.</p>
<p>I think I&#8217;ll stick with <a href="http://www.python.org">Python</a> 2.4 till more packages come to work with 2.5.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=658&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_658" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/quixote/quixote-is-not-ready-for-python-25/feed/</wfw:commentRss>
		</item>
		<item>
		<title>challenge 6, continued</title>
		<link>http://dryice.name/blog/python/python_challenge/challenge-6-continued/</link>
		<comments>http://dryice.name/blog/python/python_challenge/challenge-6-continued/#comments</comments>
		<pubDate>Mon, 08 May 2006 06:51:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python_challenge]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/challenge-6-continued/</guid>
		<description><![CDATA[A year has passed since I visited Python Challenge the last time. And it&#8217;s not easy to start it again  I&#8217;ve got a project that deals with Python image process, so I spend some time on the PIL handbook. And after that, I think trying this challenge is a good practice  
However after [...]]]></description>
			<content:encoded><![CDATA[<p>A year has passed since I visited <a href="http://www.pythonchallenge.com/">Python Challenge</a> the last time. And it&#8217;s not easy to start it again <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> I&#8217;ve got a project that deals with Python image process, so I spend some time on the <a href="http://www.pythonware.com/library/pil/handbook/">PIL handbook</a>. And after that, I think trying this challenge is a good practice <img src='http://dryice.name/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>However after I load the image</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import Image<br />
im = Image.open(&quot;channel.jpg&quot;)</div>
<p>I don&#8217;t know what to do next. I tried to exam the various attributes of the image, but got nothing.</p>
<p>Think it again on &#8220;It really looks like a Y, isn&#8217;t it? now, go back. &#8221; at <a href="http://www.pythonchallenge.com/pc/def/y.html">http://www.pythonchallenge.com/pc/def/y.html</a>. What if the zip goes back? Hmmm, it should looks like a &#8220;1&#8243; or &#8220;l&#8221;. then I tried <a href="http://www.pythonchallenge.com/pc/def/l.html">http://www.pythonchallenge.com/pc/def/l.html</a> because &#8220;1.html&#8221; has already been taken. OK, something there! &#8220;yes. but there are more. &#8221; Good! I tried 2, 3, 6, 33 &#8220;l&#8221;s and several combination with &#8220;w&#8221;, &#8220;o&#8221;, and &#8220;0&#8243;, but all 404.</p>
<p>I think now the problem is to find out how many &#8220;l&#8221;s are there. I tried every attributes of ImageStat but they are all tooooo big. No more hint. I think I should wait the next time.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=692&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_692" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/python_challenge/challenge-6-continued/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Captcha</title>
		<link>http://dryice.name/blog/python/captcha/</link>
		<comments>http://dryice.name/blog/python/captcha/#comments</comments>
		<pubDate>Mon, 17 Apr 2006 02:46:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/captcha/</guid>
		<description><![CDATA[Captcha stands for &#8220;completely automated public Turing test to tell computers and humans apart&#8221;, which is the small images we usually see when registering or logining to some systems like free email. It is developted to protect from robots. See the wikipidia page for detail.
There are several Python packages implementing this:

PyCaptcha
A cook book reciept on [...]]]></description>
			<content:encoded><![CDATA[<p>Captcha stands for &#8220;completely automated public Turing test to tell computers and humans apart&#8221;, which is the small images we usually see when registering or logining to some systems like free email. It is developted to protect from robots. See the <a href="http://en.wikipedia.org/wiki/CAPTCHA">wikipidia</a> page for detail.</p>
<p>There are several <a href="http://www.python.org">Python</a> packages implementing this:</p>
<ul>
<li><a href="http://sourceforge.net/projects/pycaptcha/">PyCaptcha</a></li>
<li>A <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440588">cook book reciept</a> on ASPN</li>
<li>And a <a href="http://captchas.net/sample/python/">sample</a> on <a href="http://captchas.net/">captchas.net</a></li>
</ul>
<p>I haven&#8217;t look them into detail but looks they are not strong enough if someone like <a href="http://sam.zoy.org/pwntcha/">pwntcha</a> want to decode it. Captcha is not a good idea according to <a href="http://www.w3.org">W3C</a>. They are working on a <a href="http://www.w3.org/TR/turingtest/">draft</a> and <a href="http://www.w3.org/TR/turingtest/">this presentation</a> explains why it&#8217;s a bad idea and provides some alternatives. Though I don&#8217;t think most of the alternatives are practive at this time.</p>
<p>Till now all the comments to my blog are from spammers, though not a big amount yet. I think I&#8217;ll imply a captcha check if it get worse.</p>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=698&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_698" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/captcha/feed/</wfw:commentRss>
		</item>
		<item>
		<title>compare strings disregarding whitespace without RE</title>
		<link>http://dryice.name/blog/python/compare-strings-disregarding-whitespace-without-re/</link>
		<comments>http://dryice.name/blog/python/compare-strings-disregarding-whitespace-without-re/#comments</comments>
		<pubDate>Tue, 21 Mar 2006 02:53:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/compare-strings-disregarding-whitespace-without-re/</guid>
		<description><![CDATA[There is an interesting topic in the python.list about comparing two strings deiregarding whitespace without re. As the discussion went on, there cames two different requirements:

normalize whitespace That is, &#8220;a\n b   c&#8221; == &#8220;a   b \n  c&#8221; but &#8220;ab c&#8221; &#60;&#62; &#8220;a bc&#8221;
totally ignore withespace Both &#8220;a\n b   [...]]]></description>
			<content:encoded><![CDATA[<p>There is an interesting <a href="http://groups.google.com/group/comp.lang.python/browse_frm/thread/2ad8fae9cc32e333/b4dc3a17d7502391">topic</a> in the python.list about comparing two strings deiregarding whitespace without re. As the discussion went on, there cames two different requirements:</p>
<ol>
<li>normalize whitespace That is, &#8220;a\n b   c&#8221; == &#8220;a   b \n  c&#8221; but &#8220;ab c&#8221; &lt;&gt; &#8220;a bc&#8221;</li>
<li>totally ignore withespace Both &#8220;a\n b   c&#8221; == &#8220;a   b \n  c&#8221; and &#8220;ab c&#8221; == &#8220;a bc&#8221;</li>
</ol>
<p>The first solution looks like this</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import string<br />
NULL = string.maketrans(&quot;&quot;,&quot;&quot;)<br />
WHITE = string.whitespace</div>
<p>def compare(a,b):<br />
&#8220;&#8221;"Compare two strings, disregarding whitespace -&gt; bool&#8221;"&#8221;<br />
return a.translate(NULL, WHITE) == b.translate(NULL, WHITE)<br />
This one first make a do-nothing translateion table and utilize string.translate to delete all the whitespaces. So this meets requirement (2).</p>
<p>However this won&#8217;t work with unicode string. This is because the plain text translate take 2 arguments and the first one is a 256 char long &#8220;translation table&#8221; returned by string.maketrans but the unicode translate takes only 1 argument and it is a dict.</p>
<p>Here is how the unicode translate works:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">&amp;gt;&amp;gt;&amp;gt; u&#8217;banana&#8217;.translate({ord(&#8217;a'):u&#8217;ay&#8217;})<br />
u&#8217;baynaynay&#8217;</div>
<p>or use it for delete:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">&amp;gt;&amp;gt;&amp;gt; u&#8217;banana&#8217;.translate({ord(&#8217;a'):None})<br />
u&#8217;bnn&#8217;</div>
<p>So for requirement (2), it looks like</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">nowhite = dict.fromkeys(ord(c) for c in string.whitespace)</div>
<p>def compare(a,b):<br />
&#8220;&#8221;"Compare two strings, disregarding whitespace -&gt; bool&#8221;"&#8221;<br />
return a.translate(nowhite) == b.translate(nowhite)<br />
It&#8217;s annoying to have these two solution for plain text and unicode. This might be why translate is marked &#8220;obsolete&#8221; in the Python documents.</p>
<p>So someone made a wrapper with the isinstance check:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import string<br />
NULL = string.maketrans(&quot;&quot;,&quot;&quot;)<br />
WHITE = string.whitespace<br />
NO_WHITE_MAP = dict.fromkeys(ord(c) for c in WHITE)<br />
def compare(a,b):<br />
&quot;&quot;&quot;Compare two basestrings, disregarding whitespace -&amp;gt; bool&quot;&quot;&quot;<br />
if isinstance(a, unicode):<br />
astrip = a.translate(NO_WHITE_MAP)<br />
else:<br />
astrip = a.translate(NULL, WHITE)<br />
if isinstance(b, unicode):<br />
bstrip = b.translate(NO_WHITE_MAP)<br />
else:<br />
bstrip = b.translate(NULL, WHITE)<br />
return astrip == bstrip</div>
<p>And for requirement (1), there is a much clever and easier way:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">def compare(a,b):<br />
return a.split() == b.splite()</div>
<p>This is because split() does all the normalize thing and splite the string with whitespace. Also this works with Unicode too.</p>
<p>Sure the Unicode translate can work for this requirement:</p>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">nowhite = dict.fromkeys(ord(c) for c in string.whitespace, &quot; &quot;)</div>
<p>def compare(a,b):<br />
&#8220;&#8221;"Compare two strings, disregarding whitespace -&gt; bool&#8221;"&#8221;<br />
return a.translate(nowhite) == b.translate(nowhite)<br />
The only change is how the dict is formed: by default dict.fromkeys will use None as the value so the whitespace is deleted, but we could replace them with a single &#8221; &#8221; so it is normalized.</p>
<p>And finially, the RE way, of cause works with Unicode:</p>
<dl>
<dd> totally ignore::</dd>
</dl>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">import re<br />
def compare(a, b):<br />
&quot;&quot;&quot;Compare two basestrings, disregarding whitespace -&amp;gt; bool&quot;&quot;&quot;<br />
return re.sub(&quot;\s*&quot;, &quot;&quot;, a) == re.sub(&quot;\s*&quot;, &quot;&quot;, b)</div>
<dl>
<dd> normalize::</dd>
</dl>
<div style="font-family: monospace;font-size: 110%; color: #000066; border: 1px solid orange; margin: 5px; padding: 5px; background-color: #ffffff;">def compare(a, b):<br />
&quot;&quot;&quot;Compare two basestrings, normalizing whitespace -&amp;gt; bool&quot;&quot;&quot;<br />
return re.sub(&quot;\s*&quot;, &quot; &quot;, a) == re.sub(&quot;\s*&quot;, &quot; &quot;, b)</div>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=713&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_713" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/compare-strings-disregarding-whitespace-without-re/feed/</wfw:commentRss>
		</item>
		<item>
		<title>playsh: MUD like programming environment for pythoner</title>
		<link>http://dryice.name/blog/python/playsh-mud-like-programming-environment-for-pythoner/</link>
		<comments>http://dryice.name/blog/python/playsh-mud-like-programming-environment-for-pythoner/#comments</comments>
		<pubDate>Tue, 21 Mar 2006 01:38:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/playsh-mud-like-programming-environment-for-pythoner/</guid>
		<description><![CDATA[There is an article on wired news about a new game, playsh. It is like a MUD but you can do python programming in it. Looks a good way to learn Python programming.
I didn&#8217;t play too much with MUD in the old 1990s days but this looks interesting. However there are two requirements for the [...]]]></description>
			<content:encoded><![CDATA[<p>There is <a href="http://www.wired.com/news/technology/0%2c70413-0.html?tw=wn_technology_4">an article</a> on wired news about a new game, <a href="http://playsh.sf.net">playsh</a>. It is like a MUD but you can do python programming in it. Looks a good way to learn <a href="http://www.python.org">Python</a> programming.</p>
<p>I didn&#8217;t play too much with MUD in the old 1990s days but this looks interesting. However there are two requirements for the package not in the <a href="http://www.freebsd.org" aiotitle="FreeBSD">FreeBSD</a> ports tree: <a href="http://www.aaronsw.com/2002/html2text/">html2text</a> and <a href="http://undefined.org/python/#simplejson">simplejson</a>. So I haven&#8217;t try it out.</p>
<p>Reference: (from the author&#8217;s blog)</p>
<ul>
<li><a href="http://interconnected.org/home/2006/03/08/playsh">What playsh is</a></li>
<li><a href="http://interconnected.org/home/2006/03/15/playsh" aiotitle="for slashdot and wired news readers">for slashdot and wired news readers</a></li>
</ul>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=714&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_714" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/playsh-mud-like-programming-environment-for-pythoner/feed/</wfw:commentRss>
		</item>
		<item>
		<title>unicode(str, &#34;utf-8&#34;) and str.encode(&#34;utf-8&#34;)</title>
		<link>http://dryice.name/blog/python/unicodestr-utf-8-and-strencodeutf-8/</link>
		<comments>http://dryice.name/blog/python/unicodestr-utf-8-and-strencodeutf-8/#comments</comments>
		<pubDate>Wed, 08 Mar 2006 16:00:00 +0000</pubDate>
		<dc:creator>dryice</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dryice.name/wordpress/index.php/uncategorized/unicodestr-utf-8-and-strencodeutf-8/</guid>
		<description><![CDATA[the key is, unicode in Python is an object, unicode(str, &#8220;utf-8&#8243;) makes that object from an utf-9 str, and str.encode(&#8221;utf-8&#8243;) encode a string to the utf-8 encoding.
To write unicode-aware python code, I&#8217;ll need to:

when getting data, use unicode(str, &#8220;the_encoding&#8221;) to get an unicode object
use unicode object inside my program, like all internal strings should be [...]]]></description>
			<content:encoded><![CDATA[<p>the key is, unicode in Python is an object, unicode(str, &#8220;utf-8&#8243;) makes that object from an utf-9 str, and str.encode(&#8221;utf-8&#8243;) encode a string to the utf-8 encoding.</p>
<p>To write unicode-aware python code, I&#8217;ll need to:</p>
<ul>
<li>when getting data, use unicode(str, &#8220;the_encoding&#8221;) to get an unicode object</li>
<li>use unicode object inside my program, like all internal strings should be u&#8221;some_thing&#8221;</li>
<li>when output, convert the unicode object to whatever fits, that is, use str.encode(&#8221;the_encoding&#8221;)</li>
</ul>
<p>Good reference:</p>
<ul>
<li><a href="http://groups.inetbot.com/showgrp/cn_pbbs_pcomp_plang_ppython_s574.html">http://groups.inetbot.com/showgrp/cn_pbbs_pcomp_plang_ppython_s574.html</a></li>
<li><a href="http://www.amk.ca/python/howto/unicode">http://www.amk.ca/python/howto/unicode</a></li>
<li><a href="http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/">http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/</a></li>
</ul>
<p><hints id="hah_hints"></hints></p>
<p class="akst_link"><a href="http://dryice.name/blog/?p=720&amp;akst_action=share-this"  title="E-mail this, post to del.icio.us, etc." id="akst_link_720" class="akst_share_link" rel="nofollow">Share This</a>
</p>]]></content:encoded>
			<wfw:commentRss>http://dryice.name/blog/python/unicodestr-utf-8-and-strencodeutf-8/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

