Instance attributes vs method arguments

Rafe rafesacks at
Tue Nov 25 11:24:57 CET 2008

> It is always good practice to provide default values for
> instance variables in the class definition, both to enhance
> readability and to allow adding documentation regarding
> the variables, e.g.
> class Class_a:
>    # Foo bar
>    a = None
>    # Foo baz
>    b = None

Those are not instance 'variables' (attributes), they are class
attributes. I used to do that in JScript, so I did it in python when I
moved over. It caused a lot of trouble for me as a beginner. I was
eventually given the advice to stop it. I haven't looked back since
(until now). I think you would just be adding a new self.a which
blocks access to your class.a, but I'm still shaky on this knowledge.

Instance attribute defaults would be inside __init__() and before
unpacking the *args.

- Rafe

More information about the Python-list mailing list