<?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>Samson&#039;s Weblog &#187; Python</title>
	<atom:link href="http://blog.samsonis.me/category/technique/python-technique/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.samsonis.me</link>
	<description>天与弗取，反受其咎；时至不行，反受其殃</description>
	<lastBuildDate>Sun, 29 Jan 2012 13:53:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python NameError: name &#8216;readline&#8217; is not defined</title>
		<link>http://blog.samsonis.me/2011/08/python-nameerror-name-readline-is-not-defined/</link>
		<comments>http://blog.samsonis.me/2011/08/python-nameerror-name-readline-is-not-defined/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 08:08:14 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[Technique]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[MacPorts]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=3386</guid>
		<description><![CDATA[Python 2.6.×已经装了有一定时日了，已经完全不知道python的世界都更新到什么境界了；标题这个issue在我更新到Lion之前就已经存在了，所以这不能算是Lion里才introduce的issue，这个还是得有一句说一句； 之前我在Snow Leopard一直没有找到fix的办法，当然主要的原因还在于我也没有那么急切的想fix它，至少对于一个几个月都基本不碰python的家伙而言，它的急迫性显然没有解决starcraft2破解版一联机就自动更新不能玩这个issue来的高，xd:) BTW, 我只玩战役模式，Blizzard及其各路partner已经完全将starcraft2的对战模式变成网游，虽然我很想支持暴雪买正版，但是网游的各种消耗对我来说是无法容忍的. 貌似又有跑题的趋势…… anyway…… 这个issue就是下面这样的，注意倒数第二行： ~ ➔ python Python 2.6.6 &#40;r266:84292, Sep 13 2010, 20:53:06&#41; &#91;GCC 4.2.1 &#40;Apple Inc. build 5646&#41; &#40;dot 1&#41;&#93; on darwin Type &#34;help&#34;, &#34;copyright&#34;, &#34;credits&#34; or &#34;license&#34; for more information. Module readline not available. Traceback &#40;most recent call last&#41;: &#160; File &#34;/Users/samson/.pythonrc&#34;, line 22, in &#60;module&#62; &#160; ...]]></description>
			<content:encoded><![CDATA[<p>Python 2.6.×已经装了有一定时日了，已经完全不知道python的世界都更新到什么境界了；标题这个issue在我更新到Lion之前就已经存在了，所以这不能算是<a href="http://blog.samsonis.me/2011/08/lion-ready/" title="Lion Ready?" target="_blank">Lion里才introduce的issue</a>，这个还是得有一句说一句；</p>
<p>之前我在Snow Leopard一直没有找到fix的办法，当然主要的原因还在于我也没有那么急切的想fix它，至少对于一个几个月都基本不碰python的家伙而言，它的急迫性显然没有解决starcraft2破解版一联机就自动更新不能玩这个issue来的高，xd:)</p>
<p>BTW, 我只玩战役模式，Blizzard及其各路partner已经完全将starcraft2的对战模式变成网游，虽然我很想支持暴雪买正版，但是网游的各种消耗对我来说是无法容忍的.</p>
<p>貌似又有跑题的趋势…… anyway……</p>
<p>这个issue就是下面这样的，注意倒数第二行：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ ➔ python<br />
Python 2.6.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span>r266:<span style="color: #000000;">84292</span>, Sep <span style="color: #000000;">13</span> <span style="color: #000000;">2010</span>, <span style="color: #000000;">20</span>:<span style="color: #000000;">53</span>:06<span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>GCC 4.2.1 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Apple Inc. build <span style="color: #000000;">5646</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>dot <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> on darwin<br />
Type <span style="color: #ff0000;">&quot;help&quot;</span>, <span style="color: #ff0000;">&quot;copyright&quot;</span>, <span style="color: #ff0000;">&quot;credits&quot;</span> or <span style="color: #ff0000;">&quot;license&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> information.<br />
Module readline not available.<br />
Traceback <span style="color: #7a0874; font-weight: bold;">&#40;</span>most recent call <span style="color: #c20cb9; font-weight: bold;">last</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:<br />
&nbsp; File <span style="color: #ff0000;">&quot;/Users/samson/.pythonrc&quot;</span>, line <span style="color: #000000;">22</span>, <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">&lt;</span>module<span style="color: #000000; font-weight: bold;">&gt;</span><br />
&nbsp; &nbsp; readline.read_history_file<span style="color: #7a0874; font-weight: bold;">&#40;</span>historyPath<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
NameError: name <span style="color: #ff0000;">'readline'</span> is not defined<br />
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span></div></div>
<p><span id="more-3386"></span><br />
主要的原因在于我起来的python cli会去读我home目录下.pythonrc <sup><a href="http://blog.samsonis.me/2011/08/python-nameerror-name-readline-is-not-defined/#footnote_0_3386" id="identifier_0_3386" class="footnote-link footnote-identifier-link" title="这个在环境变量$PYTHONSTARTUP里面设置">i</a></sup>，.pythonrc的前面几行则会试图去load readline或rlcompleter：</p>
<div class="codecolorer-container python railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">try</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">readline</span><br />
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Module readline not available.&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">else</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">rlcompleter</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">readline</span>.<span style="color: black;">parse_and_bind</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tab: complete&quot;</span><span style="color: black;">&#41;</span></div></div>
<p>而诡异的是我明明装了readline，还装了两个（当然active的只有一个），这个python却始终很傻的说找不到：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ ➔ port installed <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> readline<br />
&nbsp; readline <span style="color: #000000; font-weight: bold;">@</span>6.1.000_1+darwin<br />
&nbsp; readline <span style="color: #000000; font-weight: bold;">@</span>6.1.002_0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>
<p>我曾试图upgrade python，但是问题仍旧存在，当然真相永远只有一个……</p>
<p>不废话也不卖关子，最后的解决办法非常吐血，不是upgrade python也不是去装py-readline，而是再install一遍readline (当然最后turns out readline也升级了)：</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ ➔ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> readline</div></div>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ ➔ port installed <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> readline<br />
&nbsp; readline <span style="color: #000000; font-weight: bold;">@</span>6.1.000_1+darwin<br />
&nbsp; readline <span style="color: #000000; font-weight: bold;">@</span>6.1.002_0<br />
&nbsp; readline <span style="color: #000000; font-weight: bold;">@</span>6.2.000_0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>active<span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>
<p>problem solved:</p>
<div class="codecolorer-container bash railscasts" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">~ ➔ python<br />
Python 2.6.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span>r266:<span style="color: #000000;">84292</span>, Sep <span style="color: #000000;">13</span> <span style="color: #000000;">2010</span>, <span style="color: #000000;">20</span>:<span style="color: #000000;">53</span>:06<span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>GCC 4.2.1 <span style="color: #7a0874; font-weight: bold;">&#40;</span>Apple Inc. build <span style="color: #000000;">5646</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>dot <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> on darwin<br />
Type <span style="color: #ff0000;">&quot;help&quot;</span>, <span style="color: #ff0000;">&quot;copyright&quot;</span>, <span style="color: #ff0000;">&quot;credits&quot;</span> or <span style="color: #ff0000;">&quot;license&quot;</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">more</span> information.<br />
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span></div></div>
[Footnotes]<ol class="footnotes"><li id="footnote_0_3386" class="footnote">这个在环境变量$PYTHONSTARTUP里面设置</li></ol>
	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2010/08/terminal-app-use-option-as-meta-key/" title="Terminal.app use option as meta key (August 12, 2010)">Terminal.app use option as meta key</a> (14)</li>
	<li><a href="http://blog.samsonis.me/2011/03/terminal-app-echo-breaks-after-ctrl-c/" title="Terminal.app echo breaks after ctrl-c (March 18, 2011)">Terminal.app echo breaks after ctrl-c</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2010/09/sync-macports-ports-tree-using-subversion-over-http/" title="Sync MacPorts ports tree using Subversion (over HTTP) (September 13, 2010)">Sync MacPorts ports tree using Subversion (over HTTP)</a> (4)</li>
	<li><a href="http://blog.samsonis.me/2010/08/%e8%af%b4%e8%b0%8e/" title="说谎 (August 9, 2010)">说谎</a> (0)</li>
	<li><a href="http://blog.samsonis.me/2011/01/%e8%8a%82%e9%80%89%e4%b8%a4%e6%ae%b5%e5%a5%a5%e5%b7%b4%e9%a9%ac2011%e5%9b%bd%e6%83%85%e5%92%a8%e6%96%87/" title="节选两段奥巴马2011国情咨文 (January 26, 2011)">节选两段奥巴马2011国情咨文</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2011/08/python-nameerror-name-readline-is-not-defined/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python 2.x or 3.0</title>
		<link>http://blog.samsonis.me/2009/02/python-2x-or-30/</link>
		<comments>http://blog.samsonis.me/2009/02/python-2x-or-30/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 16:40:42 +0000</pubDate>
		<dc:creator>Samson Wu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.samsonis.me/?p=237</guid>
		<description><![CDATA[嗯，这是个问题…… 在A Byte of Python看到的评论是： If you&#8217;re wondering whether to learn Python 2.x or 3.x, then read this article by James Bennett. 貌似是从语言本身支持string Unicode，然后重组一些standard library啥的（最近老是听到restructuration一词，IT裁人不叫lay off，叫restructuration……我就短短时间内已经被restructure了两次了……），不管了，反正我也不知道2.x啥样，不compatible就不compatible:) Related posts 准备学习Python和PHP (14) ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (2) Python NameError: name &#8216;readline&#8217; is not defined (3)]]></description>
			<content:encoded><![CDATA[<p>嗯，这是个问题……</p>
<p>在<a href="http://www.swaroopch.com/notes/Python">A Byte of Python</a>看到的评论是：</p>
<blockquote><p>If you&#8217;re wondering whether to learn Python 2.x or 3.x, then <a href="http://www.b-list.org/weblog/2008/dec/05/python-3000/">read this article by James Bennett</a>.</p></blockquote>
<p>貌似是从语言本身支持string Unicode，然后重组一些standard library啥的（最近老是听到restructuration一词，IT裁人不叫lay off，叫restructuration……我就短短时间内已经被restructure了两次了……），不管了，反正我也不知道2.x啥样，不compatible就不compatible:)</p>

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://blog.samsonis.me/2009/02/%e5%87%86%e5%a4%87%e5%ad%a6%e4%b9%a0python%e5%92%8cphp/" title="准备学习Python和PHP (February 15, 2009)">准备学习Python和PHP</a> (14)</li>
	<li><a href="http://blog.samsonis.me/2010/02/rubys-python-simplehttpserver/" title="ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221; (February 21, 2010)">ruby&#8217;s &#8220;python -m SimpleHTTPServer&#8221;</a> (2)</li>
	<li><a href="http://blog.samsonis.me/2011/08/python-nameerror-name-readline-is-not-defined/" title="Python NameError: name &#8216;readline&#8217; is not defined (August 16, 2011)">Python NameError: name &#8216;readline&#8217; is not defined</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://blog.samsonis.me/2009/02/python-2x-or-30/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

