I'm trying to create a 'Polynomial' class in python, it takes an np array with polynomial coefficients as input, and needs to allow this attribute to have a 'get' and 'set' property, I'm trying to achieve this using decorators. However, when I create an instantiation of the Polynomial object it seems as though it is not using my @coefficients.setter method, because it doesn't print the string 'setting coefficients' nor does it seem to use the @coefficients.getter method as it doesn't print its string either. Am I perhaps using the decorators incorrectly? I'm using spyder as my IDE, could that be the cause of the problem?
class Polynomial ():
__coefficients = None
def __init__ ( self , coeffs ):
self.coefficients = coeffs
#INTERFACES FOR ATTRIBUTE : __coefficients
@property
def coefficients ( self ):
print('getting coefficients')
return self . __coefficients
@coefficients.setter
def coefficients ( self , coeffs ):
print('setting coefficients')
self . __coefficients = np . array ( coeffs )
self . __order = self . __coefficients . size
@coefficients . deleter
def coefficients ( self ):
del self . __coefficients
So, as an example:
\>>fx = Polynomial([0,0,1])
won't print 'setting coefficients', and
\>>fx.coefficients
won't print 'getting coefficients' also when I try to use the order attribute in other methods, I get an error saying that Polynomial has no attribute order.