Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Running python apps from within python apps

Reply
Thread Tools

Running python apps from within python apps

 
 
aph
Guest
Posts: n/a
 
      01-14-2006
Hello. I'm sure this has been asked before, but I can't find an answer
anywhere.

I want to create a truly "dynamic" app which can get new functions
"on-the-fly" and run them without having to re-start the main app.

I've found the code module that looks kind of hopefull. For instance
this works great:

import code

class myApp:

def __init__(self):
self.ii = code.InteractiveInterpreter()

def kalle(self,str):
return str.upper()

def run_script(self,script):
self.ii.runsource(script)

app = myApp()
app.run_script("print 'hello'")

Now I want this new script to interact with the existing program, and
it doesn't work. I cant for instance do:

app.run_script("print self.kalle('hello')")

Any tips of how to make this work? Is it possible?

 
Reply With Quote
 
 
 
 
Claudio Grondi
Guest
Posts: n/a
 
      01-14-2006
aph wrote:
> Hello. I'm sure this has been asked before, but I can't find an answer
> anywhere.
>
> I want to create a truly "dynamic" app which can get new functions
> "on-the-fly" and run them without having to re-start the main app.
>
> I've found the code module that looks kind of hopefull. For instance
> this works great:
>
> import code
>
> class myApp:
>
> def __init__(self):
> self.ii = code.InteractiveInterpreter()
>
> def kalle(self,str):
> return str.upper()
>
> def run_script(self,script):
> self.ii.runsource(script)
>
> app = myApp()
> app.run_script("print 'hello'")
>
> Now I want this new script to interact with the existing program, and
> it doesn't work. I cant for instance do:
>
> app.run_script("print self.kalle('hello')")
>
> Any tips of how to make this work? Is it possible?
>

I have no idea what do you want to achieve and have no experience with
PyPy myself, but I mean, that what you want to achieve should be
possible using it :

http://codespeak.net/pypy/dist/pypy/...g-started.html

Claudio
 
Reply With Quote
 
 
 
 
aph
Guest
Posts: n/a
 
      01-14-2006
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')")

Thanks...

 
Reply With Quote
 
Claudio Grondi
Guest
Posts: n/a
 
      01-14-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')")
>
> Thanks...
>

Sorry, I see, I should read your posting more carefully.

PyPy allows to run one Python interpreter in another Python interpreter
and it should even be possible to switch from one to another on the fly
- it is a bit more, than I can currently understand myself - it is a way
beyond what exec() does just running any source code passed to it in the
scope of the current script (and not the interpreter/application as such).

Claudio
P.S. my email directly to you bounced, because your mailbox reports to
be full.
 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      01-14-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C Python: Running Python code within function scope channel727272@gmail.com Python 1 09-04-2012 10:18 PM
Running Python web apps on shared ASO servers? Gilles Python 6 08-16-2012 07:59 PM
any issues with long running python apps? Les Schaffer Python 24 07-16-2010 02:13 PM
50% running mission critical apps on Linux within 5 years Aquilegia Alyssum NZ Computing 95 01-12-2007 07:19 PM
question about running desktop apps within the CLR SoftwareDummy ASP .Net 1 12-04-2003 04:41 PM



Advertisments