Question about math.pi is mutable

Chris Angelico rosuav at gmail.com
Sun Nov 8 13:01:21 EST 2015


On Mon, Nov 9, 2015 at 4:54 AM, BartC <bc at freeuk.com> wrote:
> That would be true for locals as well. But as far as I can tell from the
> CPython source code, byte-codes uses an index to represent a local, which
> represents an entry into a linear table.
>
> I can't quite see why that can't be done for global names and for attributes
> too (ie. the names that follow a ".").

At compilation time, the set of local names is locked in permanently.
That's not true of any other namespace (except nonlocals, which are
still locals, just not yours). Attributes and global names (which are
attributes of the current module) can be added and removed
dynamically, so they can't be assigned to slots; attributes can even
be simulated via __getattr__ and __getattribute__.

ChrisA



More information about the Python-list mailing list