[Tutor] declaring private attributes...
Kristoffer Erlandsson
krier115@student.liu.se
Tue Apr 29 04:16:01 2003
On Wed, Apr 30, 2003 at 02:06:49AM +0800, x wrote:
> is there a way for me to declare private, protected or static class attributes (like java)???
Private, yes (sort of). See
http://www.python.org/doc/current/tut/node11.html#SECTION0011600000000000000000
for more info.
You can not create protected attributes in Python. Everything is public or
private.
Static attributes (class attributes) are created by putting them immideately
after the "class <classname>":
>>> class A:
... sa = 1
...
>>> a = A()
>>> A.sa
1
>>> a.sa
1
>>> A.sa += 1
>>> A.sa
2
>>> a.sa
2
I'm not very familiar with java, but I'm guessing static attributes work
similar to this there.
Regards,
Kristoffer
--
Kristoffer Erlandsson
E-mail: krier115@student.liu.se
ICQ#: 378225