I don't want to disturb you, but I don't understand how works the properties. I mean, using this simple code:
#!/usr/bin/env python2.6
def cosas(self, width):
return "cosas"
class Rect(object):
def __init__(self, width, height):
self.width = width
self.height = height
self.area = 0
print "Adios"
@property
def _area(self):
return self.width * self.height
#area = property(fget=_area)
@_area.setter
def _area(self, area):
self.__area = area
@property
def _width(self):
return self.__width
@_setWidth.setter
def _setWidth(self, setwidth):
self.__width = setwidth
print cosas(self,width)
python says: NameError: name '_setWidth' is not define
I've been trying to understand the reason, but I couldn't get it. Can someone explain me how works the properties?
The last question is related with methods inside a class. Taking a look at the following code, why python says:
class Rect(object):
def __init__(self, width, height):
self.width = width
self.height = height
self.area = 0
print "Adios"
def cosas2(self, width):
return "good"
def cosas(self, width):
return cosas2(width)
>>> import prueba
>>> p = prueba.Rect(8,9)
Adios
>>> p.cosas(8)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "prueba.py", line 15, in cosas
return cosas2(width)
NameError: global name 'cosas2' is not defined
Thank you for your time.