[Tutor] Python 2 & 3 and unittest

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Sep 5 12:29:07 CEST 2013


On 5 September 2013 11:20, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>> from __future__ import division, print_function
>
> Assuming I never use the arguments of the print function, why also import print_function? print("something") works no matter if 'print' is a statement or a function.

The problem is when you want to print more than one thing i.e.

print(a, b)
  vs
print a, b

While the former isn't an error in Python 2.x it prints the tuple (a,
b) with brackets which will break any doctest. The latter form is a
syntax error in 3.x that would be dealt with by the 2to3 fixer except
you're trying to use a single codebase so that won't work for you.


Oscar


More information about the Tutor mailing list