[Python] question regarding print()

Hi,

This is weird, I wonder if someone can explain it to me.
Why is the print() function behavior different when using format or not?

a = 1
b = 2

print("Value a: ",a)
print("Value b: ",b)
print("a: {0}, b: {1}".format(a,b))

result of the above code is this:
image

Why does it print brackets in the first two lines and not the third one?

How can I configure RhinoPython to disregard “from future import print” or whtaver it is.
I want to use Brackets always when I print and not show them in the command line.

Hi,

the upper 2 prints are printing a tuple object defined after the print statement
the lower prints a string

image

Here’s an example of printing a list:
image

Does that make sense?
-Willem

Hi Wilem,

It does make sense, but why printing print(a,a) would give you again tuple.

See Python3
image

See IronPython
image

How can I make it work the same way?

Yes, how print works has changed in Python 3.

from __future__ import print function

If you really need to be P3 compatible

image

Don’t ask me, I never used it. All I know is that print changed from a statement to a function in P3. You might Google around and see how to correctly import it - if it is implemented in IronPython

1 Like

I think that __future__ module is for Python3 to copy the behavior of Python2.7 (ironpython).

And I would like it the other way around :frowning:

No, that’s not it, it’s to have Python 3 behavior in previous versions…
https://docs.python.org/2/library/future.html

I guess I just have to get used to not putting everything I print in brackets :frowning:

Apparently Guido hates brackets :smiley:

Now I think Python3 is messed up instead of an improvement:

by the way, the correct syntax is from __future__ import print_function

Yes use

from __future__ import print_function, absolute_import, division

to improve your compatibility with modern python (python 3) whilst using legacy python (2.7, e.g. RhinoPython / GHPython)

1 Like