How to import a module that must override a standard one

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ilochab

    How to import a module that must override a standard one

    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
Working...