Simulating include statement

Peter Hansen peter at engcorp.com
Thu May 8 13:11:32 EDT 2003


Gary Hubbard wrote:
> 
> I have a 15 year old application I am re-doing in python.  It is heavily
> scripted in a VERY simple minded script language I created at the time which
> has no concept of modules.  I am trying to ease the process of converting
> the scripts (which I did not write) to python.
> 
> Here's the rub.  The existing scripts have only a single global namespace,
> so a line like
>     x = 2
> in an imported module (using python terminology), act just as if the line
> appeared in the calling module.  For example,
> 
> module a:
>     x = 1
>     call b
>     print x
> 
> module b:
>    x = 2
> 
> would print the value 2.

I think the answer might depend on what you plan to do to replace "call b".
If you can provide a method call() which will itself do the import, then
you should easily be able to retrieve the namespace of the module that is
"called" and update the namespace of the caller with the modified values.

-Peter




More information about the Python-list mailing list