How to import a module that must override a standard one

ilochab ilochab at yahoo.it
Tue Mar 11 17:59:18 EDT 2008


I'm writing a python package that will contain a logging service for 
twisted in python style.
I'm using some modules I downloaded from a twisted trunk, that are not 
released with twisted but have the same names. 
One of them is log.py that is usually imported from twisted modules like:

from twisted.python import log

But I need to import __my__ log, and I need that all the other modules 
that will use my package would import __my__ log module too.
So I see 2 options to do so, but neither of them satisfies me:
1) I put __my__ log in my package tree and I import it from there, but in 
this way any other module must do the same (and this is bad for previous 
twisted application that want to use my package)
2) I oblige any potential user to patch the standard twisted installation 
with my modules, but this is even worse.

I'm quite sure there is some pythonic way to override the original 
twisted's log module after its first import with my one: I just don't 
know how to do it.

So I'll patiently wait for an answer from this group.

Ciao!
Licia



More information about the Python-list mailing list