STINNER Victor added the comment: On Linux, the locale encoding is usually UTF-8. If a filename cannot be decoded from UTF-8, invalid bytes are escaped to the surrogate range using the PEP 383. If I create a UTF-8 text file and I try to write the filename into this text file, the Python UTF-8 encoder raises an error.
IMO Python must raise an error here because I want to generate a valid UTF-8 text file, not a text file only readable by Python if the locale encoding is UTF-8. So using surrogateescape error handler if the encoding is sys.getfilesystemencoding() is *not* a good idea. What is your use case where you need to display a filename? Is it displayed to the terminal, into a file or in a graphical window? Why not escaping surrogate just to format the filename, as Gnome does? See for example: https://developer.gnome.org/glib/2.34/glib-Character-Set-Conversion.html#g-filename-display-name ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18713> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com