Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64155 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-01-17 22:24 +1100 |
| Last post | 2014-01-17 22:24 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: doctests compatibility for python 2 & python 3 Chris Angelico <rosuav@gmail.com> - 2014-01-17 22:24 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-01-17 22:24 +1100 |
| Subject | Re: doctests compatibility for python 2 & python 3 |
| Message-ID | <mailman.5635.1389957861.18130.python-list@python.org> |
On Fri, Jan 17, 2014 at 10:16 PM, Robin Becker <robin@reportlab.com> wrote:
> Aside from changing the tests so they look like
> """
> >>> func(u'aaa')==u'aaa'
> True
> """
Do your test strings contain any non-ASCII characters? If not, you
might be able to do this:
def func(a):
"""
>>> str(func(u'aaa'))
'aaa'
"""
return a
which should work in both. In Py3, the str() call will do nothing, and
it'll compare correctly; in Py2, it'll convert it into a byte string,
which will repr() without the 'u'.
I don't think it's possible to monkey-patch unicode.__repr__ to not
put the u'' prefix on, but if there is a way, that'd possibly be more
convenient.
ChrisA
Back to top | Article view | comp.lang.python
csiph-web