(Python新手,Java老家伙)我遵循了Python项目设置的建议(这里有详细说明:What is the best project structure for a Python application?)。你知道吗
我的结构是:
artman
`-- artman
+-- artman.py
+-- util.py
`-- test
`-- util_test.py
…而我的测试代码尝试导入中的内容失败利用率它将要测试:
import unittest
import util # <------ Unresolved import: util
class UtilTest( unittest.TestCase ):
def testLookForArtmanRoot( self ):
util.lookForArtmanRoot( "." )
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
我敢肯定这是一个简单的,新手Python的错误,但尽管谷歌我不知道我是否必须修改PYTHONPATH或采用其他解决方案。你知道吗
虽然这不是严格必要的,但我要澄清这个问题 目录/包/模块结构,让你学习,每一步的目的都会很清楚。你知道吗
artman_dir
添加到PYTHONPATH。你知道吗__init__.py
的空文件添加到artman_pkg
。你知道吗这两个步骤一起让你
从任何python脚本。你知道吗
然后可以在
util_test.py
using an absolute import中导入util
:其余的代码可以保持不变。你知道吗
相关问题 更多 >
编程相关推荐