Executing Python scripts in Python?

laotseu bdesth at removethis.free.fr
Tue Mar 25 18:42:03 EST 2003


Richard wrote:
> Hi,
> 
> I am currently writing an application in Python that (amongst other things)
> processes incoming data from multiple socket network connections. The
> incoming data on each socket is in a different format, although they all
> convey the same data.
> 
> I want my Python program to execute other Python scripts (in threads),
> passing to them (or making available to them) an object containing a
> connected socket and a ton of data fields for it to populate from the
> received (and processed) socket data. These scripts cannot be hard-coded
> into the appliocation as I need to be able to change the scripts while the
> main program is running.
> 
> I have seen in the Python Library Reference the 'code' module and think that
> this might be able to help me. However I can't find any examples of its use
> that applies to my situation.
> 
> Has anyone got any ideas?
> 

If you have the same interface for all your scripts, dynamic module 
loading may be what you want (have a look at the __import__ function). 
Then you use your script as if it was hard-coded.

Laotseu





More information about the Python-list mailing list