I am currently testing on a Mac a python program developed in Windows on Python 3.2. When the program is run on Windows there is no problem, but when run on a Mac I get a syntax error pointing to the following print function:
LOGFILE = open('./test.log','w')
print('Testing Started\n', file = LOGFILE)
^
SyntaxError: invalid syntax
I am running Python 3.2.2, so I think this is the correct syntax – I cannot understand what is wrong. Bizarrely, when I changes to the old 2.X syntax,
print >>LOGFILE, "Test Started\n"
it ran without error.
could there be some reason my python interpreter is using the old syntax even though it is version 3.2.2?
Thanks.
The most likely explanation is that you’re running your script using Python 2.x. There could be multiple interpreters installed on the system, so I’d suggest making sure that you’re using the interpreter that you think you’re using.
Try printing out
sys.versionfrom within your script.