Question about math.pi is mutable

Ben Finney ben+python at benfinney.id.au
Sun Nov 8 16:00:34 EST 2015


BartC <bc at freeuk.com> writes:

> I've never understood why this seems to be necessary in Python. Why do
> names have to be looked up? (I'm assuming this is searching by name in
> some sort of table.)

No, it is literally looking the name up as a key in a namespace
dictionary — which is just like any other Python dictionary, but
nominated internally for use as the namespace dictionary.

The distinction is important, because like any other dictionary it can
change at run-time and the bindings between name and value can change,
can be added, and can be removed.

> When a module is compiled, while the compiler can't see the
> definitions inside the imported modules, it /will/ know all the names
> that appear in this module, so it can organise them into fixed tables.

Not true. The namespace can change dynamically, which is another way of
what people have been trying to tell you all through this thread.

The compiler *cannot* know what the names will be at every single point
they'll be looked un in the namespace dictionary. This dynamism of each
namespace is a Python feature.

-- 
 \                  “It is … incumbent upon us to recognize that it is |
  `\    inappropriate for religion to play any role in issues of state |
_o__)        [of] a modern democracy.” —Lawrence M. Krauss, 2012-05-28 |
Ben Finney




More information about the Python-list mailing list