I’ve been teaching myself python recently an came across and example where str.endswith took a tuple as it’s first argument, which 2.4 doesn’t support. I decided to try and install a newer version of Python on my machine so I was more up to date. The machine is CentOs5.
As my user on the machine (not root) I pulled the package from here: http://www.python.org/ftp/python/2.6.7/, uncompressed it, did ./configure –prefix=/home/myusername/python/compiler/Python-2.6.7-installed, then ran make, make test (all okay) and then finally make altinstall for good measure (I know it shouldn’t be necessary to do altinstall as I specified a prefix but really don’t want to break regular python on this machine). When it first didn’t work I tried the make altinstall as root also, but it made no difference.
When I try to run a script against the binary I just get a bunch of gibberish like this:
./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((s@/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º((s@/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
and perhaps more pertinently lots of lines like these:
./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")
That is just a few random lines out of hundreds. I haven’t messed around with any of the default options, have I pulled down a funny version or specified some funny compilation options. How do I turn it off so I can just code in peace!
The code is below if anyone is interested. I just call it with ./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)
Pretty much exactly what you’re asking Python to do is happening. You’re telling it to find the word ‘asdf’ from whatever your current directory is, it’s finding it in binary files.