fartynugget007 fartynugget007 - 1 month ago 5
Python Question

Why is my Python script not running via command line?

Thanks!

def hello(a,b):
print "hello and that's your sum:"
sum=a+b
print sum
import sys

if __name__ == "__main__":
hello(sys.argv[2])


It does not work for me, I appreciate the help!!!
Thanks!

Answer

To execute your program from the command line, you have to call the python interpreter, like this: C:\Python27>python hello.py 1 1

If you code resides in another directory, you will have to set the python binary path in your PATH environment variable, to be able to run it, too. You can find detailed instructions at Adding Python Path on Windows 7

Comments