Timeline for Dynamically add member function to an instance of a class in Python
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 21, 2019 at 15:04 | comment | added | GWW | No problem. Thanks for pointing this out it's hard to remember if old answers need to be updated. | |
| Aug 21, 2019 at 15:00 | comment | added | GWW | @LudvigH: I have modified my answer to include support for python 3.X. | |
| Aug 21, 2019 at 15:00 | history | edited | GWW | CC BY-SA 4.0 |
added 206 characters in body
|
| Aug 21, 2019 at 9:41 | comment | added | LudvigH |
What python version is this for? the print statement suggest python 2.*. Doesnt work in python 3.
|
|
| Mar 31, 2014 at 1:24 | comment | added | Jules Gagnon-Marchand |
C.f = types.MethodType(f,None,C) would be the code to add the function to any existing or eventual new instances of the class C
|
|
| Jul 13, 2012 at 15:33 | comment | added | Dave |
This is the way to add the function to the specific instance a (other instances of class C won't have f).
|
|
| May 25, 2011 at 14:48 | vote | accept | Harold Forrest | ||
| May 25, 2011 at 14:48 | vote | accept | Harold Forrest | ||
| May 25, 2011 at 14:48 | |||||
| May 25, 2011 at 14:48 | vote | accept | Harold Forrest | ||
| May 25, 2011 at 14:48 | |||||
| May 25, 2011 at 1:42 | history | answered | GWW | CC BY-SA 3.0 |