[Python-3000] Recursive str

atsuo ishimoto ishimoto at gembook.org
Wed Apr 16 11:49:21 CEST 2008


2008/4/16, Michael Urman <murman at gmail.com>:
> I'll miss this, as I suspect the case of printing a list of unicode
>  strings will be fairly common. Given Unicode identifiers, even print
>  locals() could hit this. But perhaps tools for printing better
>  summaries of the contents of lists and dicts, or shell quoting (repr
>  as is makes a passable hack for quotes and spaces, but not unicode
>  characters), etc., can alleviate the pain well enough.
>
If such tools are given, but I'm not sure it is enough.
Using repr() to build output string is common practice in Python world,
so repr() is called everywhere in Python-core and third-party applications
to print objects, emitting logs, etc.,.

For example,

>>> f = open("日本語")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\ww\Python-3.0a4-orig\lib\io.py", line 212, in __new__
    return open(*args, **kwargs)
  File "c:\ww\Python-3.0a4-orig\lib\io.py", line 151, in open
    closefd)
IOError: [Errno 2] No such file or directory: '\u65e5\u672c\u8a9e'

This is annoying error message. Or, in Python 2,

>>> f = open(u"日本語", "w")
>>> f
<open file u'\u65e5\u672c\u8a9e', mode 'w' at 0x009370F8>

This repr()ed form is difficult to read. When Japanese (or Chinise)
programmers look u'\u65e5\u672c\u8a9e',  they'll have strong
impression that Python is not intended to be used in their country.


More information about the Python-3000 mailing list