我一直在教自己python最近碰到了一個例子,str.endswith帶了一個元組作爲第一個參數,它不支持2.4。我決定嘗試在我的機器上安裝更新版本的Python,以便我更新。該機器是CentOs5。關於安裝後CentOs問題的Python 2.6
正如我在機器上的用戶(不是root),我從這裏拉出了這個包:http://www.python.org/ftp/python/2.6.7/,解壓縮它,做了./configure --prefix =/home/myusername/python/compiler/Python-2.6.7-installed ,然後運行make,make test(all okay),然後最後使altinstall成爲好的措施(我知道不應該有必要做altinstall,因爲我指定了一個前綴,但實際上並不想在此機器上打破常規python) 。當它第一次沒有工作時,我也嘗試了作爲root的make altinstall,但它沒有任何區別。
當我試圖運行對二進制的腳本我只是得到這樣一堆亂碼:
./compiler/Python-2.6.7/Lib/test/test_re.pyc : onXtd}|iti|iddddgdS(Nsu" [\u002E\u3002\uFF0E\uFF61]"sa.b.cR$RHRX(R0RÑRÚR RRY(R R7(([email protected]/home/yspendiff/python/compiler/Python-2.6.7/Lib/test/test_re.pyttest_bug_931848as
Cstidd}|i|iid|it|itidd}|i|i id|i|i ddS(Ns\ssa bii(ii(ii(
StopIterationRºRR(R RRÓR tnextRR4t
Rº(([email protected]/home/yspendiff/python/compiler/Python- 2.6.7/Lib/test/test_re.pyttest_bug_581080js
cCsatidd}|i|iid|i|iid|it|idS(Ns.*tasdfii(ii(ii(RRÓR RÝRR4RÞ(R
也許更貼切很多像這樣的線路:
./compiler/Python-2.6.7/Lib/test/test_unicode.py : self.assert_(u'asdf' not in '')
./compiler/Python-2.6.7/Lib/test/test_unicode.py : self.assert_('asdf' not in u'')
./compiler/Python-2.6.7/Lib/test/test_unicode.py : self.assert_(u'asdf' not in u'')
./compiler/Python-2.6.7/Lib/test/test_re.py : iter = re.finditer(r".*", "asdf")
./compiler/Python-2.6.7/Lib/test/string_tests.py : self.checkequal(True, 'asdf', '__contains__', 'asdf')
./compiler/Python-2.6.7-installed/lib/python2.6/test/test_unittest.py : loader.loadTestsFromNames(['sdasfasfasdf'])
./compiler/Python-2.6.7-installed/lib/python2.6/test/test_unittest.py : self.assertEqual(str(e), "No module named sdasfasfasdf")
也就是說只有幾百個隨機線路。我沒有搗亂任何默認選項,我是否拉下了一個有趣的版本或指定了一些有趣的編譯選項。我如何關閉它,以便我可以和平編碼!
如果有人感興趣,代碼如下。我只是叫./Findword.py asdf:
#!/home/myusername/python/compiler/Python-2.6.7-installed/bin/python2.6
### FindWord.py
import os # for curdir() #(A)
import os.path # for join(), isfile() #(B)
import sys # for argv[], exit() #(C)
if len(sys.argv) != 2: #(D)
print "need a word or a single-quoted phrase to search for" #(E)
sys.exit(1) #(F)
def searchInFile(pattern, dirname, filenames): #(G)
for name in filenames: #(H)
name = os.path.join(dirname, name) #(I)
if os.path.isfile(name) and not name.endswith(('.pdf','.pl')): #(J)
FH = open(name, 'r') #(K)
for eachline in FH: #(L)
if (eachline.find(pattern) != -1): #(M)
print name, ': ', eachline #(N)
os.path.walk(os.curdir, searchInFile, sys.argv[1]) #(O)
「......一堆亂碼......」「'.... pyc'」回家。 – 2012-01-17 00:09:02
我在家!但是要點和經驗教訓。我所指的亂碼更多的是我運行PuTTYPuTTY時的線條和線條,我想我也應該發佈它。 – yoshiwaan 2012-01-17 00:31:12