How to pass an argument to a python program open in IDLE?

Joshua.R.English at gmail.com Joshua.R.English at gmail.com
Wed Nov 15 12:24:53 EST 2006



On Nov 15, 7:56 am, tony... at philips.com wrote:
> Hello,
>
> I have open a Python program in the IDLE, but when I select the "run
> module" under "run" menu, it
> does not allow me to pass an argument to my Python program!
> How do you pass an argument to a Python program under the IDLE? Thanks for
> you help!

I'm using Python on an old Mac with the IDE.  I think my solution would
work.

opt_parser = OptionParser()

def myfunc(argstring):
	(self.options,self.args) =
sub_opt_parser.parse_args(argstring.split())
	f not self.args: self.args = "[default arguments]".split()
	...

if __name__=="__main__":
	myfunc(argstring)


This means editing the file every time.  Since I'm on a Mac, I can also
use:
if __name__=="__main__":
	from EasyDialogs import AskString
	args = AskString('Options and Arguments')

	myfunc(args)

I'm not sure how easy this is to implement on other platforms

Josh English
Joshua.R.English at gmail.com
http://www.spiritone.com/~english




More information about the Python-list mailing list