2012-01-17 61 views
1

我一直在教自己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) 
+0

「......一堆亂碼......」「'.... pyc'」回家。 – 2012-01-17 00:09:02

+0

我在家!但是要點和經驗教訓。我所指的亂碼更多的是我運行PuTTYPuTTY時的線條和線條,我想我也應該發佈它。 – yoshiwaan 2012-01-17 00:31:12

回答

2

幾乎正是你要求Python做的事情正在發生。你要告訴它從你當前的目錄中找到'asdf'這個單詞,它會在二進制文件中找到它。

+0

是的..我只是意識到,但你到達那裏之前我可以刪除它!我正在輸入所有這些隨機字符串,比如asdkl oifuy aksjdn foiu,他們都在這樣做,所以我認爲它必須被破壞。否則Grep告訴我!當我轉換爲可以匹配的文本時,我的家庭目錄下有很多二進制文件,還有隨機字符串。 PuTTYPuTTYPuTTYPuTTYPuTTY的屏幕在我運行時會得到,但我想這只是匹配二進制文件中的一行。 基本上我是個白癡!感謝您指出了這一點! ;) – yoshiwaan 2012-01-17 00:24:08

+0

不用擔心..順便說一下,您看到的PuTTYPuTTYPUTTTY內容實際上並不在文件中,您會看到當您獲得查詢終端類型和終端響應的VT100-ish控制字符時。但是,很高興你對它進行了排序。 – synthesizerpatel 2012-01-17 00:31:15