Override a method in another module
Bruce Edge
edgebruce at yahoo.com
Tue Oct 1 19:44:42 EDT 2002
Chris Liechti wrote:
> Bruce Edge <edgebruce at yahoo.com> wrote in
> news:Fppm9.30728$V64.5796737 at newsfeed.slurp.net:
>
>> What's the basic syntax to override (redefine) a function in another
>> module at runtime?
>>
>> Say, I have module M, class C, method F, and I want to redifine method
>> F.
>>
>> setattr( M.C.F, eval("def F(self): pass")) doesn't exactly work.....
>
> and how does:
>>>> def F(self): pass
>>>> M.C.F = F #or setattr(M.C, 'F', F)
> ?
>
> hints:
> 1) setattr needs 3 args
> 2) eval works only for expressions and "def" is a keyword
>
> chris
>
Woo Hoo!!! Works !! Thank you.
I can stop banging my head on my desk now.
-Bruce.
More information about the Python-list
mailing list