Call script which accepts com. line par. from another scriptand error control

Karim Ali kakeez at hotmail.com
Thu May 24 04:22:50 EDT 2007


Hi James,

Thanks for that. That is exactly what i needed for the error control bit...

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?

If i can simply do whatever it is that parse_args() does but on a variable
of my choosing..

Karim



>From: James Stroud <jstroud at mbi.ucla.edu>
>To: python-list at python.org
>Subject: Re: Call script which accepts com. line par. from another 
>scriptand error control
>Date: Wed, 23 May 2007 17:21:47 -0700
>
>Karim Ali wrote:
> > def MAIN(expression2parse)                    <----- add a main so can
> > call from other script
>
>Of course you don't mean you want another python interpreter to fire up
>and run the other script?
>
>Here is an example of the way to do what you are suggesting:
>
># mod1.py
>
>def doit(param):
>    if not param % 37:
>      raise ValueError, 'Why u want to do dat?'
>    else:
>      print 'All right!'
>    return 'Value is: %s' % param
>
># end of mod1.py
>
>
># mod2.py
>
>import mod1
>
>print mod1.doit(20)
>print
>print mod1.doit(30)
>print
>try:
>    print mod1.doit(37)
>except ValueError:
>    print 'Gracefully handling 37....'
>    print
>print mod1.doit(37)
>
># end of mod2
>
>
>James
>--
>http://mail.python.org/mailman/listinfo/python-list

_________________________________________________________________
Fight Allergies With Live Search 
http://search.live.com/results.aspx?q=Remedies+For+Spring+Allergies&mkt=en-ca&FORM=SERNEP




More information about the Python-list mailing list