python nested class

Roland Heiber newstonne at web.de
Fri Jul 8 03:35:28 EDT 2005


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



More information about the Python-list mailing list