471,075 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Question about exec()

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
Jul 18 '05 #1
1 1100
Adonis wrote:
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

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Life is one long process of getting tired.
-- Samuel Butler
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John D. | last post: by
4 posts views Thread by D. Shane Fowlkes | last post: by
2 posts views Thread by Hul Tytus | last post: by

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.