[Tutor] pickle problems
Alan Gauld
alan.gauld at btinternet.com
Sun Aug 12 10:00:36 CEST 2012
On 12/08/12 03:43, Richard D. Moores wrote:
> ===========
> if "factors.dat":
This is testing if the string is True, which it always is.
I assume you intended something like
if os.path.exists('factors.dat'):
> f = open("factors.dat", 'rb')
> data = pickle.load(f)
> f.close
> D = data
> else:
> f = open("factors.dat", 'wb')
Not sure there is any point in opening a new file at this point. you are
trying to populate data, but if there's no file there is no data so
instead of opening the file you want something like data = {}
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list