creating package question
Micah Elliott
mde at micah.elliott.name
Wed Nov 16 15:29:12 EST 2005
On Nov 16, erick_bodine at comcast.net wrote:
> I have a package directory structure as follows
>
> root-
> |
> Common (contains __init__.py file)
> WindowsComponents (contains __init__.py file)
> ...
>
> I would like modules in the WindowsComponents directory to be able
> to import some modules from the Common directory.
So you now have a "Common" package. And it might contain a "mustard"
module.
> In my first pass, I was able to append sys.path (
> sys.path.append('../Common') ) in each module that wants to import
> from Common, but this feels "clunky".
Agreed. You probably want to avoid messing with sys.path whenever
possible.
> Is there a "standard"/"best" way to accomplish this?
So "root" should already be on your sys.path/PYTHONPATH.
Then in say file "root/WindowsComponents/spam.py":
from Common import mustard
...
mustard.attr
More import info from Fredrik:
http://effbot.org/zone/import-confusion.htm
--
_ _ ___
|V|icah |- lliott <>< mde at micah.elliott.name
" " """
More information about the Python-list
mailing list