Running python apps from within python apps

Peter Hansen peter at engcorp.com
Sat Jan 14 11:06:12 EST 2006


aph wrote:
> actually 'exec()' is the function I was looking for. Working code:
> 
> class myApp:
> 
>     def kalle(self,str):
>         return str.upper()
> 
>     def run_script(self,script):
>         exec(script)
> 
> app = myApp()
> app.run_script("print self.kalle('hello')")

A very minor point, but perhaps in some circumstances it could make a 
difference: exec is a statement, not a function.  No need to pass the 
argument(s) in parentheses, and of course there's no return value.

-Peter




More information about the Python-list mailing list