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

2009-02-20 Thread Nick Craig-Wood
Linuxguy123 linuxguy...@gmail.com 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

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

2009-02-20 Thread Bruno Desthuilliers
Nick Craig-Wood a écrit : (snip) Note that in python we don't normally bother with getA/setA normally, just use self.A, eg class Stuff(object): def __init__(self): self.A = None self.B = None def main(self): print self.A print self.B # dosomething

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

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Note that while you *can* do direct access to the implementation attribute (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't - unless you have a very compelling reason). Interesting. Why

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

2009-02-20 Thread Bruno Desthuilliers
Paddy O'Loughlin a écrit : 2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Note that while you *can* do direct access to the implementation attribute (here, '_A' for property 'A'), you don't *need* to so (and usually shouldn't - unless you have a very compelling

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

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Interesting. Why shouldn't you? I haven't used the property() function s/function/object/ Nice try, but what I wrote was what I intended to say: http://docs.python.org/library/functions.html#property For all I know I

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

2009-02-20 Thread Bruno Desthuilliers
Paddy O'Loughlin a écrit : 2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Interesting. Why shouldn't you? I haven't used the property() function s/function/object/ Nice try, but what I wrote was what I intended to say:

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

2009-02-20 Thread Paddy O'Loughlin
2009/2/20 Bruno Desthuilliers bruno.42.desthuilli...@websiteburo.invalid: Check by yourself: import inspect inspect.isfunction(property) False Using this, every single builtin function returns False. That's a pretty limited definition to be being pedantic over, especially when they are in the

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

2009-02-17 Thread Linuxguy123
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)

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

2009-02-17 Thread MRAB
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)

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

2009-02-17 Thread Paddy O'Loughlin
Use the global statement. http://docs.python.org/reference/simple_stmts.html#the-global-statement A working example based on your pseudocode would be: def getA(): global A return A def getB(): global B return B def setA(value): global A

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

2009-02-17 Thread Paddy O'Loughlin
2009/2/17 MRAB goo...@mrabarnett.plus.com: It isn't possible to have an uninitialised variable. If it doesn't have a value then it doesn't exist. True, but you can use the global statement to refer to the variable within a function and read from the variable there, without it being already

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

2009-02-17 Thread Duncan Booth
Paddy O'Loughlin patrick.olough...@gmail.com wrote: True, but you can use the global statement to refer to the variable within a function and read from the variable there, without it being already initialised in the module. You don't need the global statement unless you plan to *write* the

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

2009-02-17 Thread alex23
On Feb 18, 12:54 am, Linuxguy123 linuxguy...@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