Overriding variables used by base classes

Corey Lubin newsgroup_mail at net.aristoweb
Tue Nov 18 01:14:07 EST 2003


bokr at oz.net (Bengt Richter) wrote in news:bp3o7o$dh6$0 at 216.39.172.122:
> Still not 100% sure what you're doing, but suppose that you wanted to
> get the effect of modifying HTMLParser.py without modifying the
> original file, and be able to proceed as if your modified file were
> "myHTMLParser.py". 

Basically, yes. I want to effectively make a copy of a module and then
make adjustments to [the behaviour of] the copy, not to the original. 


> I think you could make a small actual myHTMLParser.py that starts by
> _executing_ (not importing) the code of the original HTMLParser, and
> then just modfies the result of that as desired. E.g., (untested
> beyond what you see below ;-) 

This could achieve what I want. However, I mentioned exec/eval in my
question and even then that was only in an attempt to state what I hope
I need not do. This approach strays even further down that road of by
exec'ing the entire file, getting even more complex and scary. In short,
this is not where I want to go. 


> Maybe this gives some ideas? It's not a subclass/base class thing, but
> maybe it will do what you need. Of course, you could subclass or
> rebind or whatever in the mod code (which only executes when you
> import myHTMLParser, BTW). 

No, it wasn't a sub/base class thing, but that wasn't a significant
requirement and you solved the real issue; I was just hoping for a
solution that is supported more directly by the language. 

> Regards,
> Bengt Richter

Thanks for the time you put into the suggestion. The concept of this
approach might be useful in the future. 

- Corey Lubin




More information about the Python-list mailing list