How to simulate packages?
Daniel
daniel.watrous at gmail.com
Thu Aug 21 12:04:51 EDT 2008
Hello,
I have a project that I've decided to split into packages in order to
organize my code better. So what I have looks something like this
src
-module1
-mod1_file.py
-module2
-mod2_file.py
Everytime I run mod2_file.py I need to import mod1_file.py. Right now
I'm using an ugly little thing to do my import (see below). Isn't
there some python mechanism to handle packages?
import os, sys
# add packages to path then finish importing
for dir in ['module1','module2']:
# how about this ugly thing to find adjacent directories for
imports
sys.path.append('\\'.join(os.path.dirname(__file__).split('\\')
[:len(os.path.dirname(__file__).split('\\'))-1]) + "\\" + dir)
Any and all suggestions appreciated. Thanks in advance.
Daniel
More information about the Python-list
mailing list