I've got a problem using the standard error, whenever I try to use it my computer gives me a syntax error which i can't explain.
So this is my code:
import sys
def main(argv):
if len(argv) != 3:
print("Usage: python walk.py n l", file=sys.stderr)
else:
l = argv[2]
n = argv[1]
print("You ended up", simuleer(n,l), "positions from the starting point.")
if __name__ == "__main__":
main(sys.argv)
And this is my error
MacBook-Air-van-Luuk:documents luuk$ python walk.py 5 1 2
File "walk.py", line 21
print("Usage: python walk.py n l", file=sys.stderr)
^
I hope someone can explain me why this happens, thanks in advance!
You think you're using Python 3.x, but it's actually Python 2.x. On most systems python
executable means Python 2.x.
print
is not a function in Python 2.x, and can't be used like that, causing a syntax error.
You should look for some way to run Python 3.x instead.
For this particular case, you could also use from __future__ import print_function
, which would make the code compatible with both versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With