Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bypassing parse_args() and error control

Status
Not open for further replies.

kakeez

Programmer
Dec 15, 2005
23
GB
Hi,

I would really appreciate help on this. I have a script (s1.py) which I would like to call from another script (s2.py). No problem there.

The first issue is that s1.py has a command line parser which I would like to keep but instead of fetching the information from the command line, I would like to direct the parser to get the information from a variable so i can call sp1.py from sp2.py and give it an expression to parse that normally would go on the command line. To make things clearer:

s1.py (currently) --------------------------------------------

def ...
def ...

cmdl_parser = optparse.OptionParser..
cmdl_parser.add_option..

(cmdl_opts, cmdl_args) = cmdl_parser.parse_args()

-----------------------------------------------------------------

sp1.py (the one I would like) ---------------------------------------------------------------------------------------------

def ...
def ...

def MAIN(expression2parse) <----- add a main so can call from other script
cmdl_parser = optparse.OptionParser..
cmdl_parser.add_option..

(cmdl_opts, cmdl_args) = cmdl_parser.parse_args() <---------------------------do this but on "expression2parse"

-----------------------------------------------------------------------------------------------------------------------------------


The second issue is error control. In case of an error in sp1.py I want the error handling to happen at the level of sp2.py so I can better manage things. Does anyone know how this could be done. Essentially return control to sp2.py?

I am new to Python (5 hours) but have extensive programming in C++. I would really appreciate your input.

Thanks!

Kakeez
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top