+ 12
@property and <bound method> question
I've been experimenting with the @property decorator but getting some puzzling results from this code (see the comments). Any Pythonista wisdom would be welcome š https://code.sololearn.com/ct0o1KLzZE09/?ref=app
5 Answers
+ 7
'''
I found this solution on internet, tried and it worked well.
Here link:
https://stackoverflow.com/questions/4183432/cant-set-attribute-with-new-style-properties-in-JUMP_LINK__&&__python__&&__JUMP_LINK
'''
@property
def pineapple_number(self):
return 6
@pineapple_number.setter
def pineapple_number(self,value):
'setting'
self = value
+ 7
@Ferhat and @pcrlA3 Thanks very much - that helps!
+ 7
Generally the caller of the class should not need any knowledge about internals of the class.
So in this case he should not need knowledge, how a property is implemented. (you did on two different ways)
He should be able to access mushrooms_number the same way as pineapple_number.
So - you want to call 55.() ---> no - you actually dont want.
Thanks for the question! Writing it down helps me too!
Please correct if sth. is wrong
+ 6
basically, @property is a getter by default. that's why the object is not callable.
"@property
def pineapple_number(self):
return 6" is really the same as "pineapple_number = property(pineapple_number)"
0
1 thing sololearn should include
https://www.sololearn.com/discuss/813347/?ref=app