Python handles globals badly.

Chris Angelico rosuav at gmail.com
Sat Sep 12 08:13:06 CEST 2015


On Sat, Sep 12, 2015 at 3:35 PM, Random832 <random832 at fastmail.com> wrote:
> Mark Lawrence <breamoreboy at yahoo.co.uk> writes:
>> Let's put it another way, in the 15 years I've been using Python I do
>> not recall any experienced Python programmer using "pointer", so what
>> makes you think, in 2015, that you are correct and everybody else is
>> wrong?  I still say that everything in Python is an object, and should
>> add that it has one or more things, "names", that are associated with
>> it.  Hence my preferred analogy about the sticky note.
>
> So is player3[3] also a name, a sticky note? What if we copy player3 to
> another name; does it get two sticky notes, player3[3] and foo[3]? Your
> "sticky note" analogy doesn't unify variables/names/whatever you want to
> call them with other places that you can assign stuff to, and it implies
> that the objects themselves have knowledge of their "names", and that
> names are global (if I have two functions each with a result variable,
> does that mean there are two different result sticky notes?)

Whatever you want to use to describe a name-binding reference, the
exact same thing applies to a list element or anything else. If your
analogy is strings tied to sheets of paper, with sticky notes on the
ends of strings to represent actual names, then you have similar
strings connecting list elements to their referents. (The sticky notes
aren't actually part of the objects, and you just have to understand
that you can't trace a string "backwards", only "forwards"; there's no
way to start with an object and ask "what refers to this?".)

Here. Ned Batchelder explains it better than I can.

http://nedbatchelder.com/text/names1.html
https://www.youtube.com/watch?v=_AEJHKGk9ns

ChrisA


More information about the Python-list mailing list