unicode string problems

Bengt Richter bokr at oz.net
Mon Apr 1 18:14:06 EST 2002


On Mon, 01 Apr 2002 23:41:31 +0100, Gonçalo Rodrigues <op73418 at mail.telepac.pt> wrote:

>My problem is the following:
>
>Let f be a file object. If I do
>
>f.write("Março 2002")
>
>all goes well. But if I try
>
>f.write("Março 2002" + march.Name())
>
>where march.Name() returns a unicode string I get a unicode error. I
>tried converting both unicodes to strings via str but obviously I got an
>error (in the first string the culprit is the "ç" character).
>
>Can someone help me out here and show me the way to write these strings
>to the file?
>
Someone else will be able to say OTTOTH, so I'll leave it to them (Martin?)

But it does make me think, should _all_ strings be subtypes
of a raw octet-string type according to their encoding? Then one
could visualize automatic inter-encoding promotions analogous to
numeric promotions, and if i/o sources and sinks have encoding
designators, Gonçalo's f.write("Março 2002" + march.Name()) should
"just work" if the output encoding permits. Similarly for other
string character stream destinations such as exec, eval,
and compile, of course execfile, etc.

Is this where we're heading? Just a thought ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list