pep 308: why doing (almost) nothing suffices

Graham Fawcett graham__fawcett at hotmail.com
Mon Mar 10 14:08:35 EST 2003


"Edward K. Ream" <edream at tds.net> wrote in message news:<mn0ba.2903$ES3.2330795 at kent.svc.tds.net>...
> > How about repr(s)?
> 
> I don't think so.
> 
> >>> s = 'a'
> >>> repr(s)
> "'a'"
> 
> >>> s = "a"
> >>> repr(s)
> "'a'"

Try again...

>>> a = 'xyz'
>>> print repr(a)
'xyz'
>>> a == eval(repr(a))
1
>>> b = "wxy"
>>> print repr(b)
'wxy'
>>> b == eval(repr(b))
1

The double-quoting in your example is a result of "repr'ing a repr",
since the interactive read-eval-print loop will repr() the results of
any expression, including the results of a repr() call. By explicitly
printing the results we avoid this behaviour.

-- Graham




More information about the Python-list mailing list