python 3.3 repr

Ned Batchelder ned at nedbatchelder.com
Fri Nov 15 08:54:08 EST 2013


On Friday, November 15, 2013 7:16:52 AM UTC-5, Robin Becker wrote:
> On 15/11/2013 11:38, Ned Batchelder wrote:
> ..........
> >
> > In Python3, repr() will return a Unicode string, and will preserve existing Unicode characters in its arguments.  This has been controversial.  To get the Python 2 behavior of a pure-ascii representation, there is the new builtin ascii(), and a corresponding %a format string.
> >
> > --Ned.
> >
> 
> thanks for this, edoesn't make the split across python2 - 3 any easier.
> -- 
> Robin Becker

No, but I've found that significant programs that run on both 2 and 3 need to have some shims to make the code work anyway.  You could do this:

    try:
        repr = ascii
    except NameError:
        pass

and then use repr throughout.

--Ned.



More information about the Python-list mailing list