[Tutor] Question on "import foobar" vs "from foobar import *"

bob gailer bgailer at gmail.com
Sun Jan 10 02:52:37 CET 2010


Eric Pavey wrote:
> I should add (that as I understand it), when you do a 'from foo import 
> blah', or 'from foo import *', this is doing a /copy/ (effectively) of 
> that module's attributes into the current namespace.
Not a copy (which means duplicating the attribute) but a new reference 
to the original attribute. Example
 >>> import sys
 >>> from sys import modules
 >>> sys.modules is modules
True
 >>> m = dict(sys.modules) # create a copy
 >>> m is modules
False

-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list