Hi Jamesie Thank you for your question. You asked why not > c = MyClass > o = c() > > def c.foo(cls): ... > def o.bar(self): ...
I've the same same query, but never had the courage to ask. So that you for asking. And also giving me a chance to share my thoughts. In Ruby, I believe, you can 'open up' an existing class, and add new methods to it. You can even do with core classes. I think what you asking might amount to a wish to do the same in Python. I think the Python way to 'open up' an existing class is to create a subclass, and add methods to that. Python design and development is quite pragmatic. So instead of us saying why it's not there, why don't you tell why you think it might be good idea. Based of course on examples. Particularly code taken from successful real-world applications. By the way, your >>> def o.var(self): ... won't work as you expect. To get a bound method, the method must be an attribute of the class (in other words type(o)) of the object o. That's the way Python is. What you've written does work in JavaScript. It's perhaps a bit technical and short of examples, but https://docs.python.org/3/reference/datamodel.html would be a good starting point. Can anyone else recommend some other URLs for this. Once again, thank you for asking this question. I look forward to reading other answers (and of course your response). -- Jonathan _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/