[PATCH] python3 print fixes

Douglas Bagnall douglas.bagnall at catalyst.net.nz
Tue Jan 16 20:52:47 UTC 2018

On 17/01/18 00:23, G√ľnther Deschner via samba-technical wrote:
> Hi,
> while preparing 4.8.0rc1 builds for fedora, I noticed some *new* python3
> issues which seem to be resolved with the attached patch.

Sorry for some of those.

One thing I try to do these days is start each python file with:

from __future__ import print_function

which brings the `print(x)` function to python 2.6 and 2.7, and makes
the `print x` statement a syntax error (with confusing error messages
until you get used to it).

This trains you to use the new syntax and means python 2 uses the same
print semantics as the python 3. With the __future__ import you can
end up with subtle differences -- for example:

print("a", "b")

with the py2 statement this prints a tuple:

('a', 'b')

but with the py3 function it prints a space-joined string:

a b

Which leads me to this point: shouldn't we add the __future__ import
to each file when we convert it to py3 print()? Otherwise we risk
slightly different behaviour.


PS we should probably also use `from __future__ import unicode_literals`
but that is a bit scarier in what it changes.

More information about the samba-technical mailing list