Embedding Question

Michael P. Reilly arcege at shore.net
Thu Jun 24 10:40:37 EDT 1999


Lloyd Weehuizen <tuna at delirious.fsnnet> wrote:
: Hi

: If I use the PyRun_String method, with a string that defines a method called
: "xyz", is there any way to remove this method from the Python interpreters
: "memory" without doing a Finalize() and Initialize(), because I am running
: multiple Python scripts, and I don't want there methods getting all mixed
: up, and I presume Finalize() and Initialize() are not very speedy ;)

: Thanks
: Lloyd 
: Lloyd 

Hi Lloyd,

You can use any number of the "del" based operations.  But from the
high-level (using the PyRun_* functions), you would want:
  
  int delete_function(funcname)
    char *funcname;
    { char buf[500];

      sprintf(buf, "if callable(%s):\n  del %s", funcname, funcname);
      return PyRun_String(buf);
    }

This way you can give it dotted (qualified) function names if they happen
to be in another module.

If you really wanted to get fancy, you could dynamically create modules
and run code within them.

  -Arcege





More information about the Python-list mailing list