返回顶部

收藏

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 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),

标签:Python,Database

收藏

0人收藏

支持

0

反对

0