[Python-3000] New proposition for Python3 bytes filename issue
tjreedy at udel.edu
Tue Sep 30 21:42:23 CEST 2008
Guido van Rossum wrote:
> On Tue, Sep 30, 2008 at 11:13 AM, Georg Brandl <g.brandl at gmx.net> wrote:
>> Victor Stinner schrieb:
>>> On Windows, we might reject bytes filenames for all file operations: open(),
>>> unlink(), os.path.join(), etc. (raise a TypeError or UnicodeError)
>> Since I've seen no objections to this yet: please no. If we offer a
>> "lower-level" bytes filename API, it should work for all platforms.
> I'm not sure either way. I've heard it claim that Windows filesystem
> APIs use Unicode natively. Does Python 3.0 on Windows currently
> support filenames expressed as bytes? Are they encoded first before
> passing to the Unicode APIs? Using what encoding?
In 3.0rc1, the listdir doc needs updating:
Return a list containing the names of the entries in the directory. The
list is in arbitrary order. It does not include the special entries '.'
and '..' even if they are present in the directory. Availability: Unix,
On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
will be a list of Unicode objects."
s/Unicode/bytes/ at least for Windows.
[b'countries.txt', b'multeetest.py', b't1.py', b't1.pyc', b't2.py',
b'tem', b'temp.py', b'temp.pyc', b'temp2.py', b'temp3.py', b'temp4.py',
b'test.py', b'z', b'z.txt']
The bytes names do not work however:
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
File "C:\Programs\Python30\lib\io.py", line 284, in __new__
return open(*args, **kwargs)
File "C:\Programs\Python30\lib\io.py", line 184, in open
raise TypeError("invalid file: %r" % file)
TypeError: invalid file: b'tem'
Is this what you were asking?
More information about the Python-3000