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