nick coghlan uytankmfgmailcom atsuo ishimoto wrote using repr build output string common practice python world repr called everywhere pythoncore thirdparty applications print objects emitting logs etc example f open日本語 traceback recent call last file line 1 file cwwpython30a4origlibiopy line 212 __new__ return openargs kwargs file cwwpython30a4origlibiopy line 151 open closefd ioerror errno 2 file directory u65e5u672cu8a9e annoying error message python 2 f openu日本語 w f repred form difficult read japanese chinise programmers look uu65e5u672cu8a9e theyll strong impression python intended used country starting seem like something addressed sysdisplayhookexcepthook interactive interpreter level dealt changes __repr__ implementations given following setup code def replace_escapesescaped_str return escaped_strencodelatin1decodeunicode_escape def displayhook_unicodeexpr_result expr_result none __builtins___ expr_result printreplace_escapesreprexpr_result traceback import format_exception def excepthook_unicodeexc_details msg joinformat_exceptionexc_details printreplace_escapesmsg end import sys sysdisplayhook displayhook_unicode sysexcepthook excepthook_unicode get following behaviour u65e5u672cu8a9e 日本語 printu65e5u672cu8a9e 日本語 日本語 日本語 print日本語 日本語 日本語 1 日本語 1 dir __builtins__ __doc__ __name__ __package__ displayhook_unicode excepthook_unicode format_exception replace_escapes sys 日本語 bu65e5u672cu8a9e bu65e5u672cu8a9e printbu65e5u672cu8a9e bu65e5u672cu8a9e f openu65e5u672cu8a9e traceback recent call last file line 1 file homencoghlandevelpy3klibiopy line 212 __new__ return openargs kwargs file homencoghlandevelpy3klibiopy line 151 open closefd ioerror errno 2 file directory 日本語 f openu65e5u672cu8a9e w fname 日本語 note even though bytes object representation slightly different normal displayhook doubles backslashes like bytes printing example two different representations equivalent u isnt valid escape sequence bytes literals cheers nick nick coghlan ncoghlangmailcom brisbane australia httpwwwboredomandlazinessorg _______________________________________________ python3000 mailing list python3000pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000python300040tangomucom fri 08 aug 2008 022647 1000 python3000 displaying strings containing unicode escapes interactive prompt recursive str