Peter:<br>

<br>

Thanks for the reply.  Consider the following situation:<br>

<br>

A set of variable names is defined along with a list of possible values
for each.   A second set of variable names is defined along
with an expression for generating a value for each.  For each
possible permutation of variables from the first set, a python script
is created that contains commands that initialize the variable set with
the permuted values.  A second python script is created that
contains commands for connecting to a database and storing the values
of the second set of variables after running the associated expression
for each.<br>

<br>

We would like to be able to use the scripts above to drive a python
script containing a system of equations specified at run time and to
store the results.  This "master" script contains the following
calls:<br>

<br>

import somemodule<br>

<br>

# do stuff ...<br>

<br>

# initialize permuted variables<br>

somemodule.init()<br>

<br>

# do more stuff ...<br>

<br>

# store results<br>

somemodule.save()<br>

<br>

# do more stuff ... Etc.<br>

<br>

We would like for the call to init to initialize variables in the
context of the "master" script.  To do this inside somemodule we
use the sys.modules dictionary to find a reference to the master module
by name and initialize variables at this reference.  <br>

<br>

What I would like to know if it is arbitrarily possible to "walk" the
import hierarchy from any point.  It is not apparent that python's
optimization of subsequent imports of the same module is relavent.<br><br><div><span class="gmail_quote">On 3/21/06, <b class="gmail_sendername">Peter Hansen</b> <<a href="mailto:peter@engcorp.com">peter@engcorp.com</a>
> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Eric White wrote:<br>> Is it possible to determine the name of the module that invoked import
<br>> from within the imported module?<br><br>Almost anything is possible in Python.  On the other hand, some things<br>are probably impractical, and others ill-advised.  Perhaps you can<br>describe your requirements, *why* you want to do this, to provide some
<br>context for the answers.<br><br>Also, consider that the effect of the import statement is different<br>after the first import.  When an already-imported module is imported by<br>another module (i.e. the second time "import xxx" is executed for your
<br>module), the code is not reloaded from the .pyc file, but instead a<br>reference is retrieved from sys.modules where it was cached when the<br>first import was executed.  What are you expecting to happen in that case?
<br><br>-Peter<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list</a><br></blockquote></div><br>