[Python-3000] Recursive str

Oleg Broytmann phd at phd.pp.ru
Wed Apr 16 12:32:07 CEST 2008


Hello. Sorry for being a bit late in the discussion - my sysadmin has
problems setting up our DNS server so I could not send mail.

On Tue, Apr 15, 2008 at 06:07:46PM -0400, Terry Reedy wrote:
> import unirep
> print(*map(unirep.russian, objects))
> 
> or even
> 
> from unirep import rus_print
> 
> rus_print(ojbects) # does same as above, with **kwds passed on

   First, this doesn't help anything because that form of print must be
recursive if "objects" is a container that contains other objects.

   Second, I am satisfied with how repr(objects) works - it calls repr()
recursively and that's ok. What I was complaining in the original post is
that str(objects) calls repr() for items. This is especially problematic
when I use repr() and str() semi-explicitly. For example, compare

logging.debug("objects: %r", objects)

   and

logging.debug("objects: %s", objects)

   In the first call I expect and get repr(objects), fine. But in the
second case I again get repr(), and even

logging.debug("objects: %s", str(objects))

   doesn't help.

   Do I understand it right that str(objects) calls repr() on items to
properly quote strings? (str([1, '1']) must give "[1, '1']" as the result).
Is it the only reason?

PS. atsuo ishimoto has showed that repr() is called in tracebacks. I agree
that's a problem, but that's another problem, not "recursive str".

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-3000 mailing list