Reputation: 16264
The following code runs fine in IDLE [2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)]]:
x = 5
if True:
pass
x=6
else:
x=7
print x
But in IronPython ['2.7.3 (IronPython 2.7.3 (2.7.0.40) on .NET 4.0.30319.34014 (64-bit))], the last line gives a SyntaxError: unexpected token 'print'
I copied and pasted the same lines of text in both systems, so they should be the same, including any invisible characters.
What could be the cause?
Upvotes: 0
Views: 12779
Reputation: 111
If you're doing python in VS code, always remind yourself to put bracket for print command. print(). It should be worked!
Upvotes: 0
Reputation: 51
If you have it on a Microsoft Visual Studio, then it seems that you have to have any print
commands in ()
.
So, for example:
print (dictionary_name['notreal'])
or
print (x)
Upvotes: 4
Reputation: 4611
This is a quirk of the interactive interpreter, and has nothing to do with Ironpython vs regular Python. If you save your code in a file and run it, it will work with any Python.
Here is a shorter example that shows the error:
>>> if False:
... pass
... pass
File "<stdin>", line 3
pass
^
SyntaxError: invalid syntax
When using the interactive interpreter, you must end a multi-line statement with an empty line, as so:
>>> if False:
... pass
...
>>> pass
>>>
Upvotes: 1