2012-01-17 60 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