Python class and variable issue(newby question!)

Chris Angelico rosuav at gmail.com
Fri Mar 29 18:59:22 EDT 2013


On Sat, Mar 30, 2013 at 9:51 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sat, 30 Mar 2013 08:24:00 +1100, Chris Angelico wrote:
>
>> On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry <sambez_14 at hotmail.co.uk>
>> wrote:
>>> class test()
>>>     s = 1
>>>
>>>     def test1()
>>>         global s
>>>         s = 2
>
>> That's not a global, that's a class variable.
>
>
> /me thwacks Chris with a halibut.

Ow ow ow, I give in... I am suitably and appropriately thwacked.

> Not only is "class variable" ambiguous, but Python uses different scoping
> rules for "variables" (name bindings) and attributes.

Yes, I should have said class ATTRIBUTE. Sorry all! (Can I blame the
whole 8AM and still up thing? No? Mea culpa, anyhow.)

> I don't know what language first decided to conflate object attributes
> and variables -- I suspect Java -- but it is actively harmful terminology
> (in Python at least, if not in general) and whoever invented it is bad
> and should feel bad.

Agreed. Unfortunately it permeates a lot of programmer's vocabularies,
mine included.

ChrisA



More information about the Python-list mailing list