Package that imports with name of dependent package

David Pratt fairwinds at eastlink.ca
Sat May 13 10:05:35 EDT 2006


Hi. I have code that currently depends on a particular package of a 
framework. I have decided I want to create my own package because I have 
made many changes and it is getting too difficult to maintain each time 
I retrieve an updated version of the framework from svn.

The problem is, that there are all sorts of imports to the dependent 
package throughout my code and I just want to replace this module with 
something that will provide a reference to my own package without 
changing the original imports. So it just needs to point to the new 
package so that the original imports in my code will continue to work.

For example, here is a package structure.

dependentpackage
    |
    +----  __init__.py
    +---- somemodule.py
    +---- somefolder
              |
              +----  __init__.py
              +---- somesubmodule.py
    +---- someotherfolder
    etc ....

I simply want the dependentpackage to point to the new package leaving 
no more than an init file or whatever would have to be minimally 
required to make this work

dependentpackage
    |
    +----  __init__.py

mypackage
    |
    +----  __init__.py
    +---- somemodule.py
    +---- somefolder
              |
              +----  __init__.py
              +---- somesubmodule.py
    +---- someotherfolder
    etc ....

I my code I still need to have this work:

from dependentpackage.somemodule import something

- but I want the package to be getting the code from the new module.

I'd appreciate hearing of what I can do in an __init__ file or what 
other strategy could make this work. Many thanks.

Regards,
David




More information about the Python-list mailing list