[Tutor] using class methods (security)

Paul Tremblay phthenry@earthlink.net
Thu, 25 Apr 2002 17:21:13 -0400


On Wed, Apr 24, 2002 at 10:52:58AM +0530, Karthik_Gurumurthy@i2.com wrote:

I have a few questions about this:

(1) Looking over the documentation, I have noticed that in
python 2.2, you have to subclass every class. If there is no
super class to base your new class, then you have to use the
default "(object)". Am I correct?

(2) If I am right in number (1), then I really should get python
2.2. Otherwise, I will be writing code that will eventually be
incompatible.

(3) Since my version of python (2.1) is working so well, I am
just a bit reluctant to install a new version. I am running
Mandrake 8.1 on a pentium 1 box. Has anyone out there had any
problems with installation?

Thanks!

Paul 

> > I am wondering if there is a good way to create class methods in
> > python.
> 
> python2.2 has  a way to specify static methods. There is somethign called 
> class method as well which is different from static methods which you are 
> referring to.
> 
> class test(object):
>     __count = 0
>     def __init__(self):
>         test.__count+=1
>         print test.__count
>  
>     def func(self):
>         pass
>  
>     def get_count():
>         return test.__count
>  
>     def __del__(self):
>         test.__count-=1
>  
>     get_count = staticmethod(get_count)
> 
> if __name__ == '__main__':
>     t1 = test()
>     print test.get_count()
> 
> 
> 
> 

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************