Re: python nested class
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: python nested class

From: Roland Heiber <newstonne@web.de>
Date: Fri Jul 08 2005 - 09:35:28 CEST

Vedanta Barooah wrote:
> o = mother()
> o.show()
> y=mother.child()
> y.increase(20)
> # this should print 20
> o.show()
>
> ...... is it possible somehow ???

Hi,

this should do what you want:

--- test.py
class mother:
        x=0
        def __init__(self):
                mother.x=1
        def show(self):
                print mother.x
        class child:
                def increase(self,num):
                        mother.x=num

o = mother()
o.show()
y=mother.child()
y.increase(20)
# this should print 20
o.show()

---
 >pythonw -u "test.py"
1
20
 >Exit code: 0
HtH, Roland
Received on Thu Sep 29 16:49:47 2005