Discussion:
[Tutor] Changes to dbm module/file format
Alan Gauld
2015-10-15 23:26:28 UTC
Permalink
Has anyone noticed a change to the DBM file format or is it an OS
specific thing? Last time I used dbm it was on a Windoze box with
Python 3.3 and it generated sets of 3 files for each 'database'
created. (I think this is what it did under v2 as well?)

I just used it on my Linux box in 3.4 and its only creating
a single file. Is this a 3.4 change or a Linux/dbm feature?

I can't use Python on Windows at the moment so I can't check.
Does anyone know? I don't see anything in the module docs
about file formats differing by OS...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-10-16 00:21:10 UTC
Permalink
Post by Alan Gauld
Has anyone noticed a change to the DBM file format or is it an OS
specific thing? Last time I used dbm it was on a Windoze box with
Python 3.3 and it generated sets of 3 files for each 'database'
created. (I think this is what it did under v2 as well?)
Python 2.5, under Linux:

dbm.open('foo', 'w')

creates two files:

foo.dir foo.pag


Likewise for Python 2.7.

In Python 3.3 and 3.4, you need to pass the 'c' or 'n' flag, not 'w',
and only a single file is created: "foo".
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-10-16 07:38:25 UTC
Permalink
Post by Steven D'Aprano
dbm.open('foo', 'w')
foo.dir foo.pag
Likewise for Python 2.7.
Thanks Steven.
Post by Steven D'Aprano
In Python 3.3 and 3.4, you need to pass the 'c' or 'n' flag, not 'w',
and only a single file is created: "foo".
I always used 'c' to create a new 'file' even on 2.x...

Can anyone confirm those results on Windows for 3.x please?

PS.
Although Steven only got 2 files under 2.7 a third(.bak) would be
created if he modified the contents. Hence my comment about 3
files being produced per database.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Peter Otten
2015-10-16 10:50:29 UTC
Permalink
Post by Alan Gauld
Has anyone noticed a change to the DBM file format or is it an OS
specific thing? Last time I used dbm it was on a Windoze box with
Python 3.3 and it generated sets of 3 files for each 'database'
created. (I think this is what it did under v2 as well?)
I just used it on my Linux box in 3.4 and its only creating
a single file. Is this a 3.4 change or a Linux/dbm feature?
I can't use Python on Windows at the moment so I can't check.
Does anyone know? I don't see anything in the module docs
about file formats differing by OS...
dbm in Python 3 or anydbm in Python 2 have logic to find the best available
key-value store. On Windows you are more likely to end up with the last
resort dbm.dumb (dumbdbm in py2) which uses three files (.dat, .dir, and
.bak) but I don't think that's always the case.


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Loading...