I want to know how to execute a python script using the command line. This is my code in Arithmetic.py:
def main():
print 'spam'
if __name__ == '__main__':
main()
When I type
python Arithmetic.py
I get an Syntax Error on the "c"
File "ipython-input-11-0770a0dfdadd", line 1
python Arithmetic.py
Any ideas? Thanks!
2 Answers 2
It looks like you're trying to type the python Arithmetic.py command into an IPython shell. Instead, make sure you're using your operating system's command prompt. (You can get out of a Python or IPython shell by typing exit().)
On Windows, the command prompt looks like this:
C:\Users\Carter>
On Linux, the command prompt looks like this:
carter@carters-computer:~$
In Mac OS X, it looks like this:
Carters-Macbook:~ csande$
Comments
To invoke your program from within ipython, use import Arithmetic (no '.py') in the same directory, followed by Arithmetic.main(). You can use the phrase you're currently trying to run your program from a command shell, without first starting an interpreter.
1 Comment
%run to run a file from within ipython.Explore related questions
See similar questions with these tags.
python Arithmetic.pyfrom the python shell. You use that call fromcmdorsh