class scope questions

Jay O'Connor joconnor at cybermesa.com
Fri Feb 9 17:04:37 EST 2001


Ben de Luca wrote:
> 
> if i do this
> 
> class a:
>          dog='woof'
> 
>           def blah():
>                     something
> 
> how do i call a
> how do i get soemthing in blah to refernce dog? either to read it or write
> to it

You have to declare blah() to take 'self' as an argument (which will be
the object itself) and the reference dog with 'self.dog'

Such as

	class a:
		dog = 'woof'
		
		def blah (self):
			print self.dog


Take care,

-- 
Jay O'Connor
joconnor at cybermesa.com
http://www.cybermesa.com/~joconnor

Python Language Discussion Forum -
http://pub1.ezboard.com/fobjectorienteddevelopmentpython



More information about the Python-list mailing list