I'm trying to learn Python and am trying to execute a python file in terminal. I'm using 2.7.3 python version on my OS X. I've changed the directory in terminal to where the file is located, but I'm getting an error in terminal:
>>> python ex1.py
File "<stdin>", line 1
python ex1.py
^
SyntaxError: invalid syntax
The ex1.py file contains:
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
Any ideas on how to fix this? Thx a bunch.
>>> python ex1.py
You are trying to run your script from within a python interpreter. You don't want to do that.
Instead, just run that command in a terminal, not in the interpreter
$ python ex1.py
If you are still in the interpreter, you can press ctrl+d to leave it and return to the 'normal' terminal
Exit python interpreter by typing exit()
or press Crtl+Z
You will see the terminal now.
Type python file_name.py
to run the code.
Happy coding!!!
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