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

Ben Gartner picture Ben Gartner · Jan 27, 2010 · Viewed 75.8k times · Source

I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt.

I'm running Windows.

Answer

danben picture danben · Jan 27, 2010

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/)