質問

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!

役に立ちましたか?

解決

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$

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top