473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Running python apps from within python apps

aph
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?

Jan 14 '06 #1
4 1253
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
Jan 14 '06 #2
aph
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...

Jan 14 '06 #3
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.
Jan 14 '06 #4
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

Jan 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sells, Fred | last post by:
I see there are several different choices for Python GUI API's. Is there any indication of which ones are 1. the most commonly used? 2. the most reliable? 3. the most robust?
9
by: Harald Massa | last post by:
Hello, I have a group of Python programms which I want to teach to "talk to each other". All run on Windows, on the same computer or in the same intranet. Security of communication is not an...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
7
by: Daniel Bickett | last post by:
I've been trying to convince my host to install python/mod_python on his server for a while now, however there are a number of reasons he is reluctant to do so, which I will outline here: 1. His...
17
by: los | last post by:
Hi, I'm trying to create a program similar to that of Google's desktop that will crawl through the hard drive and index files. I have written the program and as of now I just put the thread to...
2
by: Oenone | last post by:
I am developing an assembly that can be used either by a Windows Forms application or from within an ASP.NET web site. When running within the Forms app, I can break into the code while it is...
113
by: John Nagle | last post by:
The major complaint I have about Python is that the packages which connect it to other software components all seem to have serious problems. As long as you don't need to talk to anything outside...
11
by: walterbyrd | last post by:
With PHP, libraries, apps, etc. to do basic CRUD are everywhere. Ajax and non-Ajax solutions abound. With Python, finding such library, or apps. seems to be much more difficult to find. I...
34
by: Victor Kryukov | last post by:
Hello list, our team is going to rewrite our existing web-site, which has a lot of dynamic content and was quickly prototyped some time ago. Today, as we get better idea of what we need, we're...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.