[Python-porting] Porting and doctests

Lennart Regebro regebro at gmail.com
Mon Jan 5 19:27:54 CET 2009


On Mon, Jan 5, 2009 at 18:16, Daniel (ajax) Diniz <ajaksu at gmail.com> wrote:
> Hi Lennart :)
>
> Lennart Regebro  wrote:
>> When raising exceptions under 2.x, the last line of the error message
>> will look something like this:
>>
>>       ExceptionClass: The message
>>
>> But under 3.0 it will look thusly:
>>
>>       module.ExceptionClass: The message
>
> I've used "from module import ExceptionClass" in a similar case (for
> matching in a except clause, perhaps?).
>
>> When porting iCalendar, the UTF-8 encoded data that should be returned
>> for interchange will be a string in Python2, but bytes in Python3.
>> Hence,
>>
>>>>> foo()
>> "bar"
>>
>> Will fail becuase in Python 3 it should be:
>>>>> foo()
>> b"bar"
>
> I don't have 3.0 installed in this machine yet, but I believe
> foo().encode('utf-8') should work.

I seem to have explained my problems badly, as none of this answers
the questions.
My problem is that I can't write doctests that will run both under
Python 2 and Python3, because of the above mentioned changes in
behaviour, and I wonder if somebody has any hints on how to help with
that.

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64


More information about the Python-porting mailing list