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

MRAB google at mrabarnett.plus.com
Tue Feb 17 16:07:37 CET 2009


Linuxguy123 wrote:
> How do I do this in Python ?
> 
> #############################
> declare A,B
> 
> function getA
>     return A
> 
> function getB
>     return B
> 
> function setA(value)
>      A = value
> 
> function setB(value)
>      B = value
> 
> main()
>     getA
>     getB
>     dosomething
>     setA(aValue)
>     setB(aValue)
> ############################
> 
> 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 ?
> 
It isn't possible to have an uninitialised variable. If it doesn't have
a value then it doesn't exist.



More information about the Python-list mailing list