[Tutor] Structured files?

Alan Gauld alan.gauld at btinternet.com
Thu Jun 2 11:24:16 CEST 2011


"Válas Péter" <sulinet at postafiok.hu> wrote
> Modified code:
> f=open("xxx.dat","wb") The others remain as above, just I wrote wb.

Yes, you need to use binary mode.

> I read something about a pack function, is that the key?

See the file handling topic in my tutorial for a simple
example of using the struct module(which includes the
pack function) to write/read binary data.

But, pickle or shelve are probably more useful
for your needs if you want to save entire Python
objects.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list