Package that imports with name of dependent package
Peter Otten
__peter__ at web.de
Sat May 13 12:21:20 EDT 2006
Peter Otten wrote:
>> I'd appreciate hearing of what I can do in an __init__ file or what
>> other strategy could make this work. Many thanks.
>
> I think fixing the imports is the better long-term approach. But putting
>
> from pkgutil import extend_path
> import mypackage
> __path__ = extend_path(mypackage.__path__, __name__)
>
> into dependentpackage/__init__.py might work.
One big caveat: If you are mixing both
import mypackage.somemodule
and
import dependentpackage.somemodule
in the same application, mypackage.somemodule and
dependentpackage.somemodule are *not* the same module instance. This may
have surprising effects when global variables in somemodule.py are
updated...
Peter
More information about the Python-list
mailing list