member variables in python

Kent Johnson kent at kentsjohnson.com
Fri Mar 31 10:52:38 EST 2006


PyPK wrote:
> hi how do I write this better with member variables rather than global
> as you see below.
> 
> eg:
> 
> test-flag = 0
> 
> class AA:
>    def __init__(...):
> 
>   def methos(self,...):
>        global test-flag
>        test-flag = xx
> 
> instead of something like above ..how do i put it i terms of member
> variables?

class AA:
    def __init__(...):
       self.test_flag = 0

   def methos(self,...):
        self.test_flag = xx

Note 'test-flag' is not a valid name.

Kent



More information about the Python-list mailing list