When running a python script in IDLE, is there a way to pass in command line arguments (args)?

It doesn't seem like IDLE provides a way to do this through the GUI, but you could do something like:

idle.py -r scriptname.py arg1 arg2 arg3

You can also set sys.argv manually, like:

try:
    __file__
except:
    sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']

(Credit http://wayneandlayne.com/2009/04/14/using-command-line-arguments-in-python-in-idle/)


In a pinch, Seth's #2 worked....

2) You can add a test line in front of your main function call which supplies an array of arguments (or create a unit test which does the same thing), or set sys.argv directly.

For example...

sys.argv = ["wordcount.py", "--count", "small.txt"]

Here are a couple of ways that I can think of:

1) You can call your "main" function directly on the IDLE console with arguments if you want.

2) You can add a test line in front of your main function call which supplies an array of arguments (or create a unit test which does the same thing), or set sys.argv directly.

3) You can run python in interactive mode on the console and pass in arguments:

C:\> python.exe -i some.py arg1 arg2