How to 'declare' class attributes?
Neil
mac4-devnull at theory.org
Sat May 26 15:44:19 EDT 2001
Don't get class attributes and instance attrabutes mixed up. when you
say:
class foo:
val = 5
etc, you are saying that the class has a specific value. Inlike:
class foo:
def __init__(self, i):
self.val = i
where the instance of the object has a particular value. Note that all
the instances can have a different value; determined when created. but
if you say: foo.val = 50, then all the insantces of that class are
effected by that value. I guess you could condier it a global for the
class, from the instance prespective. Or a static class variable, maybe.
>From your question it sounds like you are used to something more
structured, like java or c++. Python is much more free form, which can
be hard to get used to, but ultimately leads to a much more pleasurable
coding experience.
Neil Macneale
--
To reply to me via email, remove the '-devnull' from my address.
More information about the Python-list
mailing list