If you are using a Linux Distribution, open the Terminal and type
which python
You will get a path where your default Python executable is stored. Enter this path as a first line of your code with shebang, i.e., #!
. For example, my path is: /usr/bin/python
, then I can do the following:
#! /usr/bin/python
import sys
print sys.argv
now, in your terminal, go to the directory where the file is stored. Suppose the name of the file is check.py
. Make it executable using the following command:
chmod +x check.py
Now you can run your program by typing: ./check.py arg1 arg2
and it will execute as it should.
For Windows, you need to make sure that Windows is associating the right Python executable to execute your .py
files. Even if it's associated correctly, sometimes Windows stripes off arguments from the command.
I am not a very heavy Windows user. You can check this blog: http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/