[Tutor] Structured files?

Simon Yan simonyanix at gmail.com
Thu Jun 2 10:52:53 CEST 2011


2011/6/2 Válas Péter <sulinet at postafiok.hu>:
>
>
> 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()
Try this:
f=open("xxx.dat","w")
f.write("fff")
d={'one':1, 2:'two'}
f.write(str(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?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Regards,
Simon Yan

http://www.google.com/profiles/simonyanix


More information about the Tutor mailing list