Override a method in another module

Chris Liechti cliechti at gmx.net
Tue Oct 1 19:02:17 EDT 2002


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

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list