list comprehension help

rkmr.em at gmail.com rkmr.em at gmail.com
Sun Mar 18 12:53:14 EDT 2007


On 3/18/07, Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
> In <mailman.5248.1174235057.32031.python-list at python.org>, Daniel Nogradi
> wrote:
>
> >> f = open('file.txt','r')
> >> for line in f:
> >>         db[line.split(' ')[0]] = line.split(' ')[-1]
> >>         db.sync()
> >
> > What is db here? Looks like a dictionary but that doesn't have a sync method.
>
> Shelves (`shelve` module) have this API.  And syncing forces the changes
> to be written to disks, so all caching and buffering of the operating
> system is prevented.  So this may slow down the program considerably.

It is a handle for bsddb

import bsddb
db=bsddb.hashopen('db_filename')
Syncing will defenitely slow down. I will slow that down. But is there
any improvement I can do to the other part the splitting and setting
the key value/pair?
thanks



More information about the Python-list mailing list