viric@0: #!/usr/bin/python viric@0: # -*- coding: utf-8 -*- viric@0: viric@0: import shelve,string,os viric@0: viric@0: viric@0: sourcefile = 'vortoj-ru-ca.txt' viric@0: dbfile = 'vortoj-ru-ca.sdb' viric@0: try: viric@0: os.remove(dbfile) viric@0: except: viric@0: print "File '%s' doesn't exist. Creating..." % dbfile viric@0: else: viric@0: print "File '%s' exist. Wipping..." % dbfile viric@0: viric@0: dbase = shelve.open(dbfile) viric@0: viric@0: # Read txt viric@0: file = open(sourcefile, 'r') viric@0: viric@0: for line in file: viric@0: line = line.rstrip('\n') viric@0: words = string.split(line, '\t') viric@0: print "Adding:", words[0], '=>', words[2] viric@0: dbase[words[0]] = words[2] viric@0: viric@0: file.close() viric@0: viric@0: dbase.close()