python - What is happening when I use the @func_name.setter annotation and it does not change a variable? -


I do not think my title adequately tells what I'm talking about. Take this code for example:

  & gt; & Gt; & Gt; Class D: ... x = None ... @property ... def hello (self): ... return yourself. X ... @ hello Setter ... def hello (self, text): .. Self.x = Text ... & gt; & Gt; & Gt; D = D () >> gt; & Gt; & Gt; D. Hello = 'Hello World' & gt; & Gt; & Gt; Print D. Hello hello world & gt; & Gt; & Gt; Print DX None  

Due to some reasons. Heilo and D.X do not return the same results. What's going on here

D is an old style class and therefore does not support descriptors Is: d.hello = 'hello world' does not call setter; it just creates an example feature which will be used by the descriptor D.hello . Remove from object :

  class D (object): ...  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -