How do I declare global vars or class vars in Python ?

alex23 wuwei23 at gmail.com
Tue Feb 17 22:56:21 EST 2009


On Feb 18, 12:54 am, Linuxguy123 <linuxguy... at gmail.com> wrote:
> The part I don't know to do is declare the variables, either as globals
> or as vars in a class.  How is this done in Python without setting them
> to a value ?

Generally, you can use the object None to indicate that something has
no value:

class Something(object):
    def __init__(self, a=None, b=None):
        self.a, self.b = a, b
    def dosomething(self):
        # manipulate self.a & self.b here

def main():
    s = Something("value1", "value2")
    s.dosomething()




More information about the Python-list mailing list