Importing modules
Steve Holden
steve at holdenweb.com
Thu May 12 00:46:35 EDT 2005
qwweeeit at yahoo.it wrote:
> Fredrik Lundh ha scritto:
>
>>qwweeeit at yahoo.it wrote:
>>
>>
>>>To understand a program, however, you need also a flow chart...
>>
>>so understand a carefully designed modular component structure, you
>>have to remove the structure so you can create a flow chart?
>
>
> Not everyone is a "guru" like you... I already implemented (some years
> ago) flow chart tools but for structured languages, not Object Oriented
> ones like Python.
> So forgive me if I'm in trouble... Instead of mocking me, the better
> should be to give me an brief idea of the import's roll (namespaces,
> visibility and so on...)
>
> Bye.
>
Please forgive the effbot, which has been in need of lubrication for
some time. I am happy to say that he will be offline for three minutes
and forty-six seconds tomorrow at 0945 UTC, after which we expect that
advice will be dispensed in a rather more dispassionate fashion.
According to the research team an effort to engender empathy in the
bot's behavior and thus make it more acceptable to a majority of the
Python community was found to conflict with the "can't teach an old dog
new tricks" circuitry that inherently limits the expansion capability of
all the early generation bots.
In round terms you might say that
import module
brings the named module into the current name space as a dependent name
space. Since the module is accessible by its name (in this case
"module"), names defined inside the module (normally, remember, only
executed once the first time it is imported) are available from the
importing module by qualifying the name of the desired value with the
name of the imported module. Hence
module.func(2, 3, 4)
calls the function func defined in module with three numeric arguments.
name = module.a
binds the name "name" in the local namespace to the same value currently
referenced by the name "a" in "module".
On the other hand,
from module import func, a
takes the names "func" and "a" bound (we hope) when the module was
executed on first import and binds the same names to the same values in
the current (importing) module's name space.
The usual (Python) rules for binding apply: when several names are bound
to the same mutable value all bindings reference the same object, and a
change to the referenced mutable object is seen no matter which binding
is used to access that value.
Rebinding of a name from an immutable value means it no longer
references the same object it formerly did.
regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
More information about the Python-list
mailing list