assign class variable in __init__

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Jun 8 12:55:08 EDT 2010


On Tue, 08 Jun 2010 17:24:55 +0100, Mark Lawrence wrote:

> On 08/06/2010 17:04, Ross Williamson wrote:
>> Hi Everyone,
>>
>> Just a quick question - Is it possible to assign class variables in the
>> __init__() - i.e. somthing like:
>
> They're instance variables, not class variables.

In the usual Python terminology, they're instance *attributes*. If a 
float variable is a variable storing a float, and a string variable is a 
variable storing a string, then in a language like Python where classes 
are first-class objects a class variable is a variable storing a class.

That's why Python has functions getattr, setattr and delattr, and special 
methods __getattr__ etc., rather than "getvar" etc.

I realise that other languages use "class variable" and "instance 
variable" to mean something completely different, but we don't have to 
emulate their mistakes... *wink*



-- 
Steven



More information about the Python-list mailing list