<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 28, 2017 at 11:16 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank" class="gmail-cremed gmail-cremed cremed">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm curious Why you think file names shouldn't be Unicode.  Seems pretty reasonable to me?</blockquote><div><br></div><div>Well it's certainly not unreasonable, but the underlying encoding is platform-specific. So it's not always convenient.</div><div><br></div><div>For example, it's perfectly reasonable to have filenames which are not valid UTF-8. In that case, you can just use surrogates to represent the "invalid" bytes (as Py3 does). Superficially, that just means you need to jump through more hoops to represent them; but now you have to figure out what to do with your surrogate-holding string:</div><div><br></div><div><pre style="color:rgb(0,0,0)">>>> os.listdir('/tmp/badfiles')[1]
'file-\udcff'
>>> print(os.listdir('/tmp/badfiles')[1])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 5: surrogates not allowed</pre></div><div><br></div><div>And I gather that printing the filename in the terminal is a pretty valuable target. It's all sort of a mess, frankly. :-/ The lowest common denominator remains the Posix portable filename character set.</div><div><br></div><div>(One interesting tidbit I ran across while double-checking my change was the Python test for unicode filename handling:</div><div><br></div><div><a href="https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/test/test_unicode_file_functions.py#L10">https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Lib/test/test_unicode_file_functions.py#L10</a></div><div><br></div><div>Especially the Darwin block... 4 different decompositions of each filename! I mean, it's good to cover your bases... there are just so many of them.)</div></div></div></div>