On Mar 3, 10:34 am, Chris Rebert <c...@rebertia.com> wrote: > On Tue, Mar 3, 2009 at 1:52 AM, Fab86 <fabien.h...@gmail.com> wrote: > > Hello, > > > I am new to using Python and am looking at exporting some of my code > > into a seperate document. > > > The code I am using for the pickle is: > > > file = open('testdoc.txt', 'w') > > > pickle.dump(res1.total_results_available,file) > > pickle.dump(res2.total_results_available,file) > > pickle.dump(res3.total_results_available,file) > > file.close() > > > res1.total_results_available and others are simply integers which are > > recalled from the Yahoo Search API and they print fine cmd or console > > but when trying to pickle them they are displayed like this: > > > I14 > > .I152000000 > > .I86000 > > . > > That's the contents of testdoc.txt after your program has written data > to it using pickle. With pickle's default settings, the version of the > format it uses (specifically, the oldest version) looks like that > (integers in base-10 prefixed with 'I', entries separated by a newline > and a period). It's *NOT* intended NOR guaranteed to be human-readable > (indeed, with alternate settings it uses a binary format which is > /unintelligible/ to the causal viewer). For human-readable > serialization, use the `json` module (among other possibilities). > > > > > But in console simply printing these attributes I get: > > > 14 > > 152000000 > > 86000 > > That's normal. Pickle reads in the data from the file and deserializes > it back into the proper Python objects. > > > > > Can anyone help? > > There's no problem to be solved here, just some explaining in order to > deepen your understanding. > > Cheers, > Chris > > -- > Shameless self-promotion:http://blog.rebertia.com
Thank you for your reply. Are you saying to take a look at the python json module then? I am wanting to store the integers in a file so that I can then run it through some software without having to edit it. Will json enable me to do this? Thanks again, Fabien -- http://mail.python.org/mailman/listinfo/python-list