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
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
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
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
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
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:
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 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)
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)
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
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
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
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
13 matches
Mail list logo