[Tutor] Structured files?

Válas Péter sulinet at postafiok.hu
Thu Jun 2 10:05:34 CEST 2011


2011. június 2. 9:29 Simon Yan írta, <simonyanix at gmail.com>:

> Yes you can.
> I guess the question is how you want the information to be structured.
> IMHO, everything in Python can be "string-lized".
>
> What is the syntax then?  I have Windows XP. The code is:
f=open("xxx.dat","w")
f.write("fff")
d={'one':1, 2:'two'}
f.write(d)
f.close()

Python 2.5 message:
TypeError: argument 1 must be string or read-only character buffer, not dict
Python 3.1 message:
TypeError: must be str, not dict

Modified code:
f=open("xxx.dat","wb") The others remain as above, just I wrote wb.
Python 2.5 message:
TypeError: argument 1 must be string or read-only buffer, not dict
Python 3.1 message:
    f.write("fff")
TypeError: must be bytes or buffer, not str
This won't write even a string.

I read something about a pack function, is that the key?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110602/e6fc6999/attachment-0001.html>


More information about the Tutor mailing list