Accessing one's main script's global from imported libraries
Mike Meyer
mwm at mired.org
Tue Feb 25 12:38:49 EST 2003
Alex Martelli <aleax at aleax.it> writes:
> czrpb wrote:
> > All:
> > Say I have spam.py with the global taste.
> > Say in spam.py I import eggs.
> > Say I want eggs to access spam.py's taste global.
> > How might I do this?
> You shouldn't -- it sets up the worst possible kinds of
> dependencies. But if you're really dead set on it:
>
> ===spam.py:
> taste = 23
> import eggs
>
> ===eggs.py:
> import __main__
> print __main__.taste
You can also just import spam instead of eggs. Mutual imports like
that require a little care, but can work.
<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