← Back to DAGDA |
Support | Source: https://mail.python.org/pipermail/python-porting/2017-September/000529.html
[Python-porting] repr() with same output on Python2.7 and Python3.x
Chris Jerdonek
chris.jerdonek at gmail.com
Mon Sep 18 14:09:50 EDT 2017
This doesn't seem possible in general because __repr__() can contain
arbitrary code, and it could have different logic depending on whether it's
being executed in Python 2 or 3. Is there a more constrained question you
can ask, maybe for the repr of certain types of objects?
There are also various hacks you could do, like in your test equality
checker, replace "u'" with "'" in the given string before comparing.
--Chris
On Mon, Sep 18, 2017 at 10:59 AM Thomas Güttler <
guettliml at thomas-guettler.de> wrote:
> Hi,
>
> I have a Python 2.7 code base before me, where some tests contain the
> output of repr().
>
> On Python2.7 I see u'foo' and on Python3 I see 'foo'.
>
> This is the reason why some tests fail.
>
> Is there a repr() which outputs the same string on Python2.7 and Python3?
>
> It would be nice if I could get the Python3 output on Python2.7
>
> Regards,
> Thomas Güttler
>
> --
> Thomas Guettler http://www.thomas-guettler.de/
> _______________________________________________
> Python-porting mailing list
> Python-porting at python.org
> https://mail.python.org/mailman/listinfo/python-porting
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-porting/attachments/20170918/bdb45707/attachment.html>
More information about the Python-porting
mailing list