Passing command line argument to program from within IDLE?

John Bokma john at castleamber.com
Fri Feb 5 00:40:41 CET 2010


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:

> On Thu, 04 Feb 2010 16:28:17 -0500, Steve Holden wrote:
>
>> Terry Reedy wrote:
>>> On 2/4/2010 3:55 PM, Alan Biddle wrote:
>>>> Just finishing my first Python (2.6 on Win XP)  program, which is
>>>> working fine.  My "Duh?" question is about how to run it from within
>>>> IDLE and pass it command line arguments.  No problem using sys.argv
>>>> from a Windows command line, but I have missed how you can do that
>>>> from within IDLE, which complicates development and debugging.
>>> 
>>> I presume you mean edit, F5-run, see result in shell window. Set
>>> sys.argv in test function or __name__=='__main__' In 3.1 idle shell:
>>> 
>>>>>> import sys
>>>>>> sys.argv
>>> ['']
>>>>>> sys.argv = ['abc','dev']
>>>>>> sys.argv
>>> ['abc', 'dev']
>>> 
>>> I did not know it was writable, either, until I tried it.
>>> 
>> As a solution, however, that sucks, wouldn't you agree?
>
> [scratches head]
>
> Do you mean setting sys.argv as a solution sucks? No, I don't, I think it 
> is grand. If sys.argv was unmodifiable, *that* would suck.
>
> Or do you mean that trying it as a solution to the problem of answering 
> the OP's question sucks? Well, no, experimentation is good for answering 
> these sorts of questions, and I can't assume that the documentation will 
> cover every imaginable use-case, or that users will find it. In the 
> absence of any documentation stating otherwise, I would have assumed that 
> sys.argv was an ordinary list which you can modify at will, but having 
> been caught out on faulty assumptions before, I would try it and see 
> before commenting publicly.

I guess that Terry means that a solution that makes it possible to
specify in IDLE *outside* of the Python code the arguments would be
better. Hardcoding the command line arguments isn't something I would do
for testing.

-- 
John Bokma                                                               j3b

Hacking & Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development



More information about the Python-list mailing list