Writing a function from within Python
George Sakkis
george.sakkis at gmail.com
Wed May 28 18:10:41 EDT 2008
On May 28, 4:39 pm, Aaron Scott <aaron.hildebra... at gmail.com> wrote:
> Is it possible to change the content of a function after the function
> has been created? For instance, say I make a class:
>
> class MyClass:
> def ClassFunction(self):
> return 1
>
> And I create an object:
>
> MyObject = MyClass()
>
> Is there any way to change the content of the function, a la pseudo-
> code:
>
> MyObject.ClassFunction = "return 2"
>
> Thanks for any insight you might be able to offer.
The short answer is "yes". The longer answer is "yes but most likely
there are better approaches to whatever you want to do". If you give a
bit more context of the general problem you're trying to solve, I'm
sure you'll get more helpful replies.
George
More information about the Python-list
mailing list