Find a word in shelve file,findshelve,import sys,
Find a word in shelve file,findshelve,import sys,
import sys, shelve, linecacheshIn = shelve.open('indexfiles')for word in sys.argv[1:]: if not shIn.has_key(word): sys.stderr.write('Word %r not found in index file\n' % word) continue places = shIn[word] for fname, lineno in places: print 'Word %r occurs in line %s of file %s:' % (word,lineno,fname) print linecache.getline(fname, lineno),
- hex literals,literals,print 0x01,
- Reading a binary File,readingbinaryfile,f = open('/m
- Slicing works similar to strings; use the square bracket
- Read a file line by line and check line separator,chec
- Looping Over Characters with read Writing the Loop Diffe
- Text files: iterating over the lines in the file,itera
热门文章:
相关内容
- hex literals,literals,print 0x01,
- Reading a binary File,readingbinaryfile,f = open('/m
- Slicing works similar to strings; use the square bracket slice operat
- Read a file line by line and check line separator,checkseparator,im
- Looping Over Characters with read Writing the Loop Differently,loop
- Text files: iterating over the lines in the file,iteratinglines,f =
- Reading the entire file at once,readingentire,print '\nRea
- Creating a text file with the writelines() method.,creatingwritelin
- Dates are easily constructed and formatted,,#Dates and T
- Return the current working directory,workingdirectory,import ospri
评论关闭