我有这样的文件结构:
project/
__init__.py
common/
__init__.py
util.py
utilhelper.py
stuff/
__init__.py
coolstuff/
__init__.py
awesome.py
import utilhelper
help = utilhelper.help()
from common import util
print util.help
当我这样做的时候:
python project/stuff/coolstuff/awesome.py
“from common import util”失败,并显示“没有名为common的模块”。在
我意识到我错过了一些非常重要的心理概念,比如路径和包装,因为我不知道如何解决这个问题。但如果可能的话,我希望将类似“from common import util”的代码保存在deep子目录中。在
我考虑过: -设置Paver以将路径依赖项注入通过sh运行python脚本的任务:
@task
@needs(['common'])
def dostuff():
sh('python stuff/coolstuff/awesome.py')
不幸的是,我不知道我在做什么,也找不到任何好的例子/教程。在
-在我的脚本中使用imp显式导入相对和/或绝对文件路径
在每个python文件的顶部插入一个小的python写路径
我真的很感激你的建议。在
作为快速解决方案,我:
相关问题 更多 >
编程相关推荐