Generic access to DBM-style databases : DBM « Database « Python






Generic access to DBM-style databases

Generic access to DBM-style databases

import fileinput, os, anydbm
wordPos = {}
sep = os.pathsep
for line in fileinput.input():
    pos = '%s%s%s'%(fileinput.filename(), sep, fileinput.filelineno())
    for word in line.split():
        wordPos.setdefault(word,[]).append(pos)

dbmOut = anydbm.open('indexfile','n')
sep2 = sep * 2
for word in wordPos:
    dbmOut[word] = sep2.join(wordPos[word])
dbmOut.close()

           
       








Related examples in the same category

1.DBM Demo
2.store and fetch data by key