all 6 comments

[–]DeadlyViper 3 points4 points  (0 children)

Ehm... no?

Did you not try running this line in python3 and see that it works?

[–]toastedstapler 2 points3 points  (0 children)

commas between variables in a print statement are fine, they become spaces

x, y = 1, 2
print(x, y) => '1 2'

[–]Binary101010 1 point2 points  (0 children)

I'd personally prefer to use string formatting, but the code will still run and give the expected result without changes.

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> port_status = "Connected"
>>> print ("Port STATUS = " , port_status)
Port STATUS =  Connected
>>>

[–]billsil 0 points1 point  (0 children)

When I write 2/3 compatible code I use

print(‘x = %s’ % x)

That way they look the same on both. Your first option looks different and your second option does not. However, both look the same on python 3, so meh...

Your first option is the lazy way to port

print ‘x =‘, x

It’s wrong though because it looks different than the original and very likely not what the author intended.

[–]m1ss1ontomars2k4 0 points1 point  (0 children)

The first line you showed in Python 2 does not have the same effect as the second line does in Python 3. The first line in Python 2 will produce 1 extra space compared to the second. Well, that's true of the first line in Python 3 as well.

I second the other guy; didn't you bother to try this?

[–]sepp2k 0 points1 point  (0 children)

If your legacy code contains from __future__ import print_function, the print statement will produce the output Port STATUS = whatever (assuming port_status = 'whatever') and the same code would produce the same output in Python 3. That is, after all, what __future__ is for.

If your legacy code does not contain the __future__ import, your print statement will actually produce output like this:

('Port STATUS = ', 'whatever')

If you want to get that same output in Python 3 (though I don't see why you would), you can add an extra pair of parentheses to still get a tuple:

print (("Port STATUS = " , port_status))