python - Mixin class to trace attribute requests - __attribute__ recursion -
I am trying to create a class that others should have a superclass, tracing their property requests, Thought of using getattribute ", which attributes all the feature requests, but it generates recursive:
class Mixin (object): def __getattribute__ (self, attr): print I know why I get recurring: it's for myself dict calls that remember
> retrieve I "return item .__ getattribute __ (self, etter) "Has tried to change the last line in
as suggested in other posts but the recurrence is remembered.
try this:
class Mixin (object): def __getattribute__ (Self, atri): print itself, "getting", attr back object .__ Getattribute __ (self, attr)
If you are still having recurring problems, The reason is that you have not shown us
& gt; & Gt; & Gt; Square compile (object): ... def __getattribute__ (auto, attr): ... print itself, "meet", et ... return object .__ getattribute __ (self, entree) ... & gt; & Gt; & Gt; Mixin () .__ str__ & lt; __ Main __. Mixed object at 0x00B47870 & gt; 0x00B47870 __str__ of the mixin object & lt; Method-wrapper is being '__str__' & gt; & Gt; & Gt; & Gt; Mixen (). Fauber & lt; __ Main __. Mixed object at 0x00B47670 & gt; Foobre traceback (most recent call final) is happening: file "& lt; stdin>", line 1, & lt; Module & gt; Error in the file "& lt; stdin & gt;", line 4, __getattribute__ attribute: 'feature' object, 'fiber' & gt; & Gt; & Gt;
And here's the result when Bob's
> gt; & Gt; Class mylist (mix): ... def __init__ (self, list): ... if not (lista) == type (""): ... self.value = lista [...] ... def __add__ (self, some): ... back to self Price ... something ... def __getitem__ (auto, item): ... back to self Value [item] ... def __getslice__ (auto, beg, end) :. .. return self Price [Request:]] ...> gt; & Gt; A = Myलिस्ट ([1,2])> gt; & Gt; & Gt; A.value & lt; __ Main __. Mylist object 0x00B47A90 & gt; Getting the price [1, 2]
Comments
Post a Comment