Python in a nutshell
class B(object): def f(self): return 23 g = property(f) class C(B): def f(self): return 42 c = C() print(c.g) # prints: 23, not 42 ... the property does not search for this name , but uses the function object that it passed at creation time.If you need to work around this problem, you can always do this by adding an additional search level:class B(object): def f(self): return 23 def _f_getter(self): return self.f() g = property(_f_getter) class C(B): def f(self): return 42 c = C() print(c.g) # prints: 42, as expected Here, the function object held by this property is B._f_getter, which in turn searches for the name f (since it calls self.f ()) ;
class B(object): def f(self): return 23 g = property(f) class C(B): def f(self): return 42 c = C() print(c.g) # prints: 23, not 42
... the property does not search for this name , but uses the function object that it passed at creation time.
If you need to work around this problem, you can always do this by adding an additional search level:
class B(object): def f(self): return 23 def _f_getter(self): return self.f() g = property(_f_getter) class C(B): def f(self): return 42 c = C() print(c.g) # prints: 42, as expected
Here, the function object held by this property is B._f_getter, which in turn searches for the name f (since it calls self.f ()) ;
What does search mean?
Under what conditions does a “search” take place?
What is the rule that determines that a property does not perform a search, but self.f()does?
self.f()
Thank.
"" " , ". , , .
, property(f), , B. , f . f , obj.g, f ( ).
property(f)
B
f
obj.g
, property(_f_getter), - , _f_getter - . _f_getter , obj.g, _f_getter . , _f_getter self ( self.f).
property(_f_getter)
_f_getter
self
self.f
, : " ". , , , , . , , , .
Source: https://habr.com/ru/post/1680252/More articles:multiple function definition - c ++Can I avoid the `eval (parse ())` function definition with `polyomial ()` in R? - rИндексировать два набора столбцов в массиве - pythonHow to load data in Meteor app using Redux? - reactjsReact Day Picker calendar overlay event appears behind other components - reactjsHow to manage Meteor.user () in the configuration of Meteor-React-Redux? - reactjshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1680254/passing-fixed-size-eigen-matrices-as-arguments-to-function-calling-for-dynamic-size-matrices&usg=ALkJrhgF1J2NN9FviI_C21v6OUHfi7-YpAsparklyr write data in hdf or hive - sparklyrUsing Contact Form 7 via WP REST API - wordpressRSA decryption of AES session key fails: AttributeError: 'bytes' object has no attribute 'n' - pythonAll Articles