Need to create module with virtual functions to mirror another module

Paul Keating keating at acm.org
Sat Dec 14 07:04:20 EST 2002


I'm working with embedded Python.

A new version of the environment has changed the way that Python functions
are called: it now passes all parameters in a list as a single argument.

We have a large number of Python modules that have functions coded to the
old calling sequence. The simple solution is to write a set of new modules
that contain wrapper functions for the old modules, like this:

# module newstyle
import oldstyle

def myfunc(args):
  return oldstyle.myfunc(*args)

But because this is such a mechanical translation, there ought to be a way
to consult the globals() function in oldstyle and create these functions on
the fly in newstyle. Finding the functions in oldstyle and creating the
wrappers isn't too hard. But what I can't work out is how to make the new
functions in newstyle accessible by modules that import newstyle.

I suspect what I need is an import hook, but the docs, and ihook, are way
over my head. Is there a very basic tutorial on import hooks out there?





More information about the Python-list mailing list