txt2db.py
author viric <viriketo@gmail.com>
Sun, 13 Feb 2011 08:27:44 +0100
changeset 4 a3d29fb016c3
parent 0 6371497b4e53
permissions -rwxr-xr-x
Adding handling of tab and enter
#!/usr/bin/python
# -*- coding: utf-8 -*-

import shelve,string,os


sourcefile = 'vortoj-ru-ca.txt'
dbfile = 'vortoj-ru-ca.sdb'
try:
	os.remove(dbfile)
except:
	print "File '%s' doesn't exist. Creating..." % dbfile
else:
	print "File '%s' exist. Wipping..." % dbfile

dbase = shelve.open(dbfile)

# Read txt
file = open(sourcefile, 'r')

for line in file:
	line = line.rstrip('\n')
	words = string.split(line, '\t')
	print "Adding:", words[0], '=>', words[2]
	dbase[words[0]] = words[2]

file.close()
	
dbase.close()