Call script which accepts com. line par. from another scriptanderror control

Karim Ali kakeez at hotmail.com
Thu May 24 08:28:06 EDT 2007


>Karim Ali wrote:
>
> > What I still dont know though is how do I handle the fact that the first
> > script is expecting command line parameters. I would like to be able to
> > replace the command line parameters by a variable such that the second
> > script can call: first_script.main("command line"). Is this possible?
>
>I think it is better to pass a list of arguments
>
># first_script.py
>
>def main(args=None):
>     parser = optparse.OptionParser()
>     # add options
>     options, positional_args = parser.parse_args(args)
>     # process
>
>if __name__ == "__main__":
>     # will read options from the command line
>     # if module is invoked as a standalone script
>     main()
>
># second_script.py
>
>import first_script
>first_script.main(["-f", "--bar", "what", "you want"])
>
>That way you don't have to deal with escaping spaces etc.
>
>Peter
>
>--
>http://mail.python.org/mailman/listinfo/python-list

Thanks Peter. That does the trick!

Karim

_________________________________________________________________
New Windows Live Hotmail is here. Upgrade for free and get a better look. 
www.newhotmail.ca?icid=WLHMENCA150




More information about the Python-list mailing list