Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Are you actually trying to add methods to instances at runtime? The 1. argument to function.__get__() should be the instance that a method is bound to (passed as the 1. argument, usually self) and you're passing the function itself. The exception points this out: "'function' object has no attribute ...". Commented Jun 13, 2016 at 7:49
  • 1
    Feels like this might be an XY problem. What are you actually trying to achieve by dynamically adding methods to class instances? Why do you think you need to do this? Commented Jun 13, 2016 at 7:53
  • After reading your edit, I don't really understand what you want to achieve. Do not ask a new question about it because it would probably be too broad, but you should add more context, mainly explain how you want to use that. I'm used to Spring's ApplicationContext, and I'm sure it is not the way they are built... Commented Jun 13, 2016 at 16:24
  • @SergeBallesta Its funny that you mention that, Spring was one of the things that lead me to exploring this functionality in Python. I've added some further clarifications, perhaps you can suggest a better way to replicate Spring & Lombok within Python Commented Jun 14, 2016 at 15:14
  • 1
    Python annotation on classes could mimic some of Lombok's features, notably automatic getters and setters... except that Python uses properties instead of getters and setters, but a class annotation could generate all the boiling plate code around a property (this could lead to a SO question IMHO). For Spring, you could look at pinject for an example of DI implementation in Python... Commented Jun 14, 2016 at 15:49