Re: [Python-Dev] just say no...

Recently, Greg Stein <gstein@lyra.org> said:
Oops... I remember the discussion but I wasn't aware that somone had actually _implemented_ this:-). Part of my misunderstanding was also caused by the fact that I inspected what I thought would be the prime candidate for t#: file.write() to a non-binary file, and it doesn't use the new format. I also noted a few inconsistencies at first glance, by the way: most modules seem to use s# for things like filenames and other data-that-is-readable-but-shouldn't-be-messed-with, but binascii is an exception and it uses t# for uuencoded strings... -- Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++ Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++ www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm

I guess that's because file.write() doesn't distinguish between text and binary files. Maybe it should: the current implementation together with my proposed semantics for Unicode strings would mean that printing a unicode string (to stdout) would dump the internal encoding to the file. I guess it should do so only when the file is opened in binary mode; for files opened in text mode it should use an encoding (opening a file can specify an encoding; can we change the encoding of an existing file?).
Actually, binascii seems to do it right: s# for binary data, t# for text (uuencoded, hqx, base64). That is, the b2a variants use s# while the a2b variants use t#. The only thing I'm not sure about in that module are binascii_rledecode_hqx() and binascii_rlecode_hqx() -- I don't understand where these stand in the complexity of binhex en/decoding. --Guido van Rossum (home page: http://www.python.org/~guido/)

I guess that's because file.write() doesn't distinguish between text and binary files. Maybe it should: the current implementation together with my proposed semantics for Unicode strings would mean that printing a unicode string (to stdout) would dump the internal encoding to the file. I guess it should do so only when the file is opened in binary mode; for files opened in text mode it should use an encoding (opening a file can specify an encoding; can we change the encoding of an existing file?).
Actually, binascii seems to do it right: s# for binary data, t# for text (uuencoded, hqx, base64). That is, the b2a variants use s# while the a2b variants use t#. The only thing I'm not sure about in that module are binascii_rledecode_hqx() and binascii_rlecode_hqx() -- I don't understand where these stand in the complexity of binhex en/decoding. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum
-
Jack Jansen