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

James Stroud jstroud at mbi.ucla.edu
Wed May 23 20:21:47 EDT 2007


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



More information about the Python-list mailing list