About 350,000 results
Open links in new tab
  1. Adding a Method to an Existing Object Instance - Stack Overflow

    Aug 4, 2008 · #!/usr/bin/python -u import types import inspect ## dynamically adding methods to a unique instance of a class # get a list of a class's method type attributes def listattr(c): for m in …

  2. add method to loaded class/module in python - Stack Overflow

    Oct 13, 2011 · In Python classes are just regular objects and a class method is just a function stored in an object attribute. Attributes of object instances in Python moreover are dynamic …

  3. python - Dynamically adding methods to a class - Stack Overflow

    Oct 26, 2012 · Here is the issue, print_v here is considered bound method.But when print_v is defined in a different module such that the namespace is module.print_v, for some reason it …

  4. How can I dynamically create class methods for a class in python

    @patch_methods(MyClass) class MyClassPatcher(MethodPatcher): def extra_method_a(self): print('a', self) @classmethod def extra_class_method_b(cls): print('c', cls) # !!ATTENTION!! the …

  5. How to add a classmethod in Python dynamically - Stack Overflow

    And notice that your code most probably fails because you are calling the SadClass.say_dynamic() before any instances are created, and thus before the class method …

  6. python - Method __add__ in a class - Stack Overflow

    Nov 17, 2015 · If you want your __add__ method to return a new instance of MyNum, and continue to pass in that value to the constructor, it will have to accept it as part of its __init__. …

  7. Any elegant way to add a method to an existing object in python ...

    May 18, 2015 · This is a somewhat elegant way to add a method to an existing object (without needing to change its class and without affecting other existing objects). Follow-up to …

  8. python - How to print instances of a class using print ... - Stack …

    A simple decorator @add_objprint will help you add the __str__ method to your class and you can use print for the instance. Of course if you like, you can also use objprint function from the …

  9. python - How to add method using metaclass - Stack Overflow

    Sep 22, 2014 · How to add custom method to Python class? 1. Use class method not instance method with the same name. 0.

  10. Can I add custom methods/attributes to built-in Python types?

    You can do this in ruby too by simply opening up the class again, ie: class String; def new_method()...;end; I'm pretty sure python has something like that too. – Abdullah Jibaly …

Refresh