Re: member variables in python
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: member variables in python

From: Fredrik Lundh <fredrik@pythonware.com>
Date: Fri Mar 31 2006 - 18:20:08 CEST

"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>
Received on Sun Apr 30 21:47:50 2006