Ben Gartner Ben Gartner -5 years ago 141
Python Question

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

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 Source

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

You can also set sys.argv manually, like:

    sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download