Question about exec()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adonis

    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


  • Erik Max Francis

    #2
    Re: Question about exec()

    Adonis wrote:
    [color=blue]
    > 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.[/color]

    Maintain a separate globals dictionary and give it to exec:

    exec code in myGlobals

    --
    __ Erik Max Francis && max@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

    Comment

    Working...