member variables in python

Fredrik Lundh fredrik at pythonware.com
Fri Mar 31 18:20:08 CEST 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?

you mean something like

    class AA:

        def __init__(self):
            self.test_flag = 0 # initialize

        def methods(self, value):
            self.test_flag = value

    # ...

    aa = AA()
    aa.methods(1)
    print aa.test_flag

?

</F>






More information about the Python-list mailing list