command-line arguments in IDLE
thunderfoot at gmail.com
thunderfoot at gmail.com
Wed Nov 7 16:50:35 EST 2007
On Nov 7, 6:27 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
> Is it possible to pass command-line arguments when running a program
> in IDLE? The "Run" menu does not seem to provide that option. Thanks.
Can't you just fake the command line args by setting sys.argv? This
isn't too sophisticated, but it appears to work:
import sys
try:
__file__
except:
sys.argv = ['scriptname.py', 'this','is','a','test','within','idle']
for arg in sys.argv:
print arg
Running from within IDLE:
>>>
scriptname.py
this
is
a
test
within
idle
>>>
Running from the command prompt:
C:\Python24>python.exe mystuff/argtest.py this is yet another test
mystuff/argtest.py
this
is
yet
another
test
C:\Python24>
HTH,
Don
More information about the Python-list
mailing list