Question about exec()

A

Adonis

I wrote a small webserver and a small html parser to parse some elements, in
which contain python code, now before I go any further your thinking "not
another web application server" and before being routed to Twisted, Zope,
Webware, Mod_Python, etc., this is a learning project, it is for my amusment
and better understanding. Nevertheless, inside the html document I have
python enclosed in <? ?> tags, and it executes fine, but if I have a few of
those tags I would like that prior executions stay in memory of the same
document, instead of having to load X module everytime I wish to execute the
code in the same document.

To ellaborate further:
(same document)

<some html code here>
<?
import sys
print sys.version
?>
<some more html code>
<?
print sys.platform
?>

Any help is greatly appreciated.

Adonis
 
E

Erik Max Francis

Adonis said:
Nevertheless, inside the html document I have
python enclosed in <? ?> tags, and it executes fine, but if I have a
few of
those tags I would like that prior executions stay in memory of the
same
document, instead of having to load X module everytime I wish to
execute the
code in the same document.

Maintain a separate globals dictionary and give it to exec:

exec code in myGlobals
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top