This question has (for me) no real implication. I just found this out by coincidence and I am curious about the mechanics behind it. I got the folling example script:
#!/usr/bin/env python
"""
just an example
"""
class exampleClass():
'this is just an example'
if __name__ == '__main__':
print(__doc__)
Running this in eclipse print “just an example”. However, when I try to run this in the terminal I get the following error:
File "./temp.py", line 6
class exampleClass():
^
SyntaxError: invalid syntax
Now, when I change the class in the example script to inherit from dict
class exampleClass(dict):
and run it from the commandline it also prints “just an example”.
So why do classes have to inherit something to work from commandline, but not from eclipse?
According to the Python 2.7.2 grammar, the following syntax is incorrect:
It should be either
or
In all probability you’re using two different versions of the Python interpreter, and for some reason one of the interpreters is allowing the invalid syntax and the other isn’t.