problems with shelve

Nemesis nem at nowhere.invalid
Mon Oct 4 13:54:25 CEST 2004


I used shelve to build a dictionary with 100 elements. I saved the file
(on Linux) and reaopened it on Windows, but I noticed a strange
behaviour. 
Let's call dic the shelve opened, the command "len(dic)" returned 89 but
"len(dic.keys())" "len(dic.values())" "len(dic.items())" returned 100.

I dumped the shelve on a real dictionary and then I dumped this
dictionary in to another shelve. len() on this new shelve returned 93.

Alex Martelli told me that probably I should open the file in binary
mode on Windows ... but I don't know how.

This is the syntax of shelve.open:

open( filename[,flag='c'[,protocol=None[,writeback=False[,binary=None]]]]) 

binary is deprecated, and however I tried it but nothing changed.
flag refers to the opening for reading/writing ...
protocol is the protocol used by cPickle

How can manage on different platforms the same shelve?

-- 
XPN :: http://xpn.altervista.org




More information about the Python-list mailing list