import from question
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Wed Jan 16 21:35:39 EST 2008
On Wed, 16 Jan 2008 15:31:54 -0800, Tobiah wrote:
>> Again, those aren't copies. There is only one instance of each value,
>> referenced by multiple names.
>
>
> Ok, I get it. I was locally importing a pointer to an integer
Really? What language were you using? Python doesn't have pointers.
Some *implementations* of Python (e.g. CPython) might have pointers *in
the implementation*, but others (e.g. PyPy, Jython) don't.
> which is
> really the same object as the module name points to, but the assignment
> changes that. The confusion for me centered around the fact that a local
> name can be used to change values in mutables that are visible from
> within the module. This however, does not include assignment to the
> local name.
If you haven't already done so, you should read:
http://effbot.org/zone/python-objects.htm
http://effbot.org/zone/call-by-object.htm
and remember that imports are (more or less) equivalent to assignments.
When you do this:
>>> import module
it is roughly equivalent to:
>>> module = get_a_module_from_file_name('module')
Alternatively:
>>> from module import foo
is roughly equivalent to:
>>> temp = get_a_module_from_file_name('module')
>>> foo = temp.foo
>>> del temp
(and the magic function "get_a_module_from_file_name" is actually called
__import__ with double underscores.)
--
Steven
More information about the Python-list
mailing list