[Python-3000] Recursive str

Jason Orendorff jason.orendorff at gmail.com
Wed Apr 16 18:05:01 CEST 2008


On Tue, Apr 15, 2008 at 10:30 PM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Terry Reedy wrote:
>  > import unirep
>  > print(*map(unirep.russian, objects))
>
>  That's okay if the objects are strings, but what about
>  non-string objects that contain strings?
>
>  We'd need another protocol, such as __unirep__.

Or have str.__repr__() respect per-thread settings, the way decimal
arithmetic does.

Default settings would be in force most of the time; the interactive
prompt would apply the user's settings when repr-ing a result.  This
approach solves the nested-strings problem quite nicely.  But it does
not catch error/warning/log messages when they are generated, unless
the program does *everything* under custom repr settings (dangerous).

There really are two use cases here: a human-readable repr for
error/warning/log messages; and a machine-readable, always-the-same,
ASCII-only repr.  Users want to be able to tweak the former.

-j


More information about the Python-3000 mailing list