jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

python print() function bug #283

Closed Enrique-ZA closed 4 years ago

Enrique-ZA commented 4 years ago
myname, mysurname = "John", "Smith"
print ("I am ", myname, mysurname)

Output: ('I am ', 'John', 'Smith')

The correct output is:

I am John Smith

The above code is the same as using:

myname, mysurname = "John", "Smith"
print ("I am " + myname + " " + mysurname)

Output: I am John Smith

This is also the same as:

myname, mysurname = "John", "Smith"
print ("I am " + str(myname) + " " + str(mysurname))

Output: I am John Smith

villares commented 4 years ago

Hi @Enrique-Za!

This is not a bug because in Python 2 print is not a function, and Processing Python Mode is based on Jython (Python 2), so you are using the print statement followed by a tuple!

Check https://docs.python.org/3/whatsnew/3.0.html to have a better picture. Then you can have the Python 3 behaviour using this first thing in yout sketch:

from __future__ import print_function
Enrique-ZA commented 4 years ago

Hi @villares, sorry, my mind is so used to python3, that I didn't even stop to think it might be python2 based. Thanks for clearing that up!