assign class variable in __init__

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Jun 8 16:36:34 EDT 2010


On 08/06/2010 17:55, Steven D'Aprano wrote:
> 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*
>
Yes alright bloody Aussies  ** n * sodit * *wink*.  Not sure if this is 
a syntax error, but too lazy too test at an interactive prompt.

Kindest regards.

Mark Lawrence.




More information about the Python-list mailing list