atsuo ishimoto dsuvthimgembookorg ive written pep new string representation python 3000 patch updated httpbugspythonorgissue2630 guido updated patch rietveld httpcodereviewappspotcom767 would appreciate comments help pep 3138 title string representation python 3000 version revision lastmodified date author atsuo ishimoto status draft type standards track contenttype textxrst created 05may2008 posthistory abstract pep proposes new string representation form python 3000 python prior python 3000 repr builtin function converts arbitrary objects printable ascii strings debugging logging python 3000 wider range characters based unicode standard considered printable motivation current repr converts 8bit strings ascii using following algorithm convert cr lf tab r n convert nonprintable characters0x000x1f 0x7f nonascii characters0x80 xxx backslashescape quote characters add quote character head tail unicode strings following additional conversions done convert leading surrogate pair characters without trailing character 0xd8000xdbff followed 0xdc000xdfff uxxxx convert 16bit characters0x100 uxxxx convert 21bit characters0x10000 surrogate pair characters u00xxxxxx algorithm converts string printable ascii repr used handy safe way print strings debugging logging although nonascii characters escaped matter strings characters ascii languages japanese characters string ascii inconvenient python 3000 lot nice features nonlatin users nonascii identifiers would helpful python could also progress similar way printable output users might concerned output mess console print binary data like images unlikely happen practice bytes strings different types python 3000 printing image console wont mess issue discussed hyeshik chang 1_ rejected specification algorithm build repr strings changed convert cr lf tab r n convert nonprintable ascii characters0x000x1f 0x7f xxx convert leading surrogate pair characters without trailing character 0xd8000xdbff followed 0xdc000xdfff uxxxx convert unicode whitespace ascii spacex20 control characters categories z c unicode database xxx uxxxx u00xxxxxx set unicode errorhandler sysstdout sysstderr backslashreplace default rationale repr python 3000 unicode ascii based like python 3000 strings also conversion affected locale setting locale necessarily output devices locale example common daemon process invoked ascii setting writes utf8 log files characters supported users console hexescaped printing unicode encoders errorhandler errorhandler output file backslashreplace characters hexescaped without raising unicodeencodeerror example default encoding ascii print prints xa2 encoding iso88591 printed printable characters unicode standard doesnt define nonprintable characters must create definition propose define nonprintable characters follows nonprintable ascii characters python 2 broken surrogate pair characters characters defined unicode character database cc control cf format cs surrogate co private use cn assigned zl separator line u2028 line separator zp separator paragraph u2029 paragraph separator zs separator space ascii spacex20 characters category escaped avoid ambiguity alternate solutions help debugging nonlatin languages without changing repr suggestion made supply tool print lists dicts strings printed debugging contained lists dicts also many types object file objects contain file name unicode exception objects contain message unicode etc strings printed readable form repred unlikely possible implement tool print possible object types use sysdisplayhook sysexcepthook interactive sessions write hooks restore hex escaped characters original characters hooks called result evaluating expression entered interactive python session doesnt work print function noninteractive sessions subclass sysstdout sysstderr difficult implement subclass restore hexescaped characters since isnt enough information left time string undo escaping correctly cases example printu0041 printed u0041 chance tell file objects apart make encoding used unicode_repr adjustable benefit preserving current repr behavior make applicationlibrary authors aware nonascii repr selecting encoding printing flexible global setting open issues lot people use utf8 encoding example en_usutf8 de_deutf8 cases backslashescape trick doesnt work backwards compatibility changing repr may break existing codes especially testing code five pythons regression test fail modification need repr strings without nonascii character python 2 use following function def repr_asciiobj return strreprobjencodeascii backslashreplace ascii reference implementation httpbugspythonorgissue2630 references 1 multibyte string stringstring_print httpbugspythonorgissue479898 copyright document placed public domain _______________________________________________ python3000 mailing list python3000pythonorg httpmailpythonorgmailmanlistinfopython3000 unsubscribe httpmailpythonorgmailmanoptionspython3000python300040tangomucom fri 08 aug 2008 200807 0900 python3000 pep 3108 string representation python 3000