Accessing one's main script's global from imported libraries
Mike Meyer
mwm at mired.org
Wed Feb 26 13:51:40 EST 2003
Alex Martelli <aleax at aleax.it> writes:
> Mike Meyer wrote:
> > Alex Martelli <aleax at aleax.it> writes:
> > You can also just import spam instead of eggs. Mutual imports like
> > that require a little care, but can work.
> Assuming you mean "import spam from eggs"
Right...
> Now when you run "python spam.py" you will see [23] printed.
> If you edited eggs.py to use spam instead of __main__, then
> when you ran "python spam.py" it would print the empty list
> [] twice -- eggs.py would have imported spam.py again under
> the new and different name 'spam', a distinct copy from the
> one that is loading under the name '__main__'. Try it...
Oh, I believe you. I did say they require some care. You've found one
of the areas that don't work quite right.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list