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
self.A = "aValue"
self.B = "aValue"
print self.A
print self.B
a = Stuff()
a.main()
None
None
aValue
aValue
If you need (later) A to be a computed value then you turn it into a
property, which would look like this. (Note the main method is
identical to that above).
class Stuff(object):
def __init__(self):
self._A = None
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).
--
http://mail.python.org/mailman/listinfo/python-list