system(...) and unicode
"Martin v. Löwis"
martin at v.loewis.de
Mon May 22 18:39:07 EDT 2006
andrew at acooke.org wrote:
> Hmmm. After reading
> http://kofoto.rosdahl.net/trac/wiki/UnicodeInPython I tried:
>
> system(cmd.encode(getfilesystemencoding()))
>
> which works (nothing else changed). But that seems odd - is this a bug
> (the asymmetry - I read files with os.listdir with no explicit unicode
> handling, but need to do something explicitly on output - seems wrong),
> or am I going to be bitten by other errors later?
Whether or not listdir returns a Unicode string depends on whether you
pass a Unicode string as the directory name. So if you change the
directory name to be a byte string, the file name should be a byte
string, too.
And yes, it would be desirable to enhance system() to support Unicode
strings; contributions in that direction are welcome (although one
should then also support exec*(), spawn*(), popen*(), and the subprocess
module).
Regards,
Martin
More information about the Python-list
mailing list