decorator - Python: Overriding a Unknown class -


इस उदाहरण पर विचार करें:

  x = a.some_class_instance x.foo ()   

मैं x.foo ()

की तर्ज पर कुछ करना चाहता हूं

  @ x Foo () def dec () प्रिंट 'डेकोरेटर' x.foo ()   

क्या ऐसा करने के लिए कोई रास्ता है? धन्यवाद:)

आसान तरीका यह करना है:

  X.foo = dec (x.foo)   

उदाहरण के वर्ग का विस्तार करने का दूसरा तरीका

  x = a.some_class_instance वर्ग विस्तारित (x .__ class__ ): @ डीईसीटी एफई (...): ...   

लेकिन मुझे ऐसा करने का कोई अच्छा कारण नहीं देख सकता।

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -