[PATCH] python3 print fixes

Alexander Bokovoy ab at samba.org
Tue Jan 16 21:06:00 UTC 2018

On ke, 17 tammi 2018, Douglas Bagnall via samba-technical wrote:
> 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.
I think we should add that, indeed.

> Douglas
> PS we should probably also use `from __future__ import unicode_literals`
> but that is a bit scarier in what it changes.
Since authors suggest its use for backporting rather than forward
porting, I think we better stay away from it.

/ Alexander Bokovoy

More information about the samba-technical mailing list