import from question

Terry Reedy tjreedy at udel.edu
Wed Jan 16 15:12:53 EST 2008


"Ben Finney" <bignose+hates-spam at benfinney.id.au> wrote in message 
news:87tzleb2st.fsf at benfinney.id.au...
| Tobiah <toby at tobiah.org> writes:
|
| > This is a little surprising. So "from mod import *" really copies
| > all of the scalars into new variables in the local namespace.

'Scalar' is not a Python term.  Neither is 'object pointer' really,
except in respect to the CPython implementation.

| No. Nothing is copied. All the objects (remembering that in Python,
| *everything* is an object) created by the code in module 'mod' are
| given names in the current namespace.

To amplify, 'from mod import *' is, I believe, more or less equivalent to

import mod
for name in mod.__all__
   exec "%s = mod.%s" % name,name
del mod

except, of course, that the imported module would not actually be bound to 
'mod'
(and need deleting) so that there is no conflict with mod containing the 
name 'mod'.







More information about the Python-list mailing list