Find a word in shelve file : Shelve : Database PYTHON examples


PYTHON examples » Database » Shelve »

 

Find a word in shelve file




import sys, shelve, linecache
shIn = shelve.open('indexfiles')

for word in sys.argv[1:]:
    if not shIn.has_key(word):
         sys.stderr.write('Word %r not found in index filen' % 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),


           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Database
» Shelve