Question

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!

Was it helpful?

Solution

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$

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top