importing symbols from module objects

Peter Hansen peter at engcorp.com
Wed Sep 26 02:01:22 EDT 2001


Paul Rubin wrote:
> 
> "Sean 'Shaleh' Perry" <shalehperry at home.com> writes:
> > when you try to get around the language, "weird" calls is all you have.  You
> > example may not truly reflect what you are trying to do because:
> >
> > from EggsBaconSpam import breakfast, SpamException
> >
> > gives you what you want and has only the one line to change.
> 
> There's lots of different classes in EggsBaconSpam.py.  I don't
> want to import all its symbols into the caller's namespace--just
> a few of them.  The other ones, I want to refer to as provider.symbolname.

import EggsBaconSpam
from EggsBaconSpam import breakfast, SpamException

That does precisely what you ask above, with only two reasonably
elegant lines of code.  Pure Python, nothing weird.

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list