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.
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 from veganaiZe produces a KeyError outside IDLE with python 3.6.3. This can be solved by replacing
if sys.modules['idlelib']:
byif 'idlelib' in sys.modules:
as below.In a pinch, Seth's #2 worked....
For example...
import sys
sys.argv = [sys.argv[0], '-arg1', 'val1', '-arg2', 'val2']
//If you're passing command line for 'help' or 'verbose' you can say as:
sys.argv = [sys.argv[0], '-h']
This code works great for me, I can use "F5" in IDLE and then call again from the interactive prompt:
...
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:
Based on the post by danben, here is my solution that works in IDLE: