[Tutor] a db question

William N Carey bcarey@ix.netcom.com
Sun, 10 Jun 2001 19:47:40 -0700


Hi all,

I'm new to Python.  I love Python, and recently tried 
using it to do a very simple database project,  but perhaps my 
expectations were unrealistic. Using Python 2.0 on a Win2000
machine with 256M Ram and many gigs of disk space, I couldn't 
successfully load a text file which consists of a 12 character key 
and a 38 character text string as the record.  The problem is that 
the file consist of  about 800,000 records.  I used  "anydb" which 
on my machine uses bsddb as the default (I believe).  After about 
120,000 records the load would halt with
an "error: (0, 'error')"  .  The key and text string are normal.  I can 
start the reload a couple of records short of where it blew up, and it 
continues for another 100,000 or so records, and blows up again, 
until it finally halts at about 400,000 records with a hard halt 
(invoking my Visual C++ debugger).

I built in a file.sync instruction which happens every 10,000 
records, and this didn't help.

I suspect that I am asking the "db" routines to do too much, but 
that is disappointing to me, because Python has always done 
whatever I wanted in my limited past with it.  Below is the very 
simple program that doesn't finish.

Thanks for any advice!!!

import os, anydbm
ofile = anydbm.open("e:\\python20\\lib\\wnctrans","c")
ifile = open("e:\\python20\\lib\\wncdet","rb")
fin = ifile.fileno()
for x in range(0,783284):
   if x % 10000 == 0:
      ofile.sync
   print x
   ptr = os.lseek(fin,x * 50, 0)
   wstr = os.read(fin,50)
   if len(wstr) == 50:
      key12 = str(wstr[:12])
      item = str(wstr[12:])
      ofile[key12] = item
os.close(fin)
print "Done..."
dum = raw_input("any key")
ofile.clo