有人可以帮我这个吗?
我正在继续使用PyDev Aptana开发python代码.这是我在PyDev IDE下的项目结构:
/testProject
/src
/testModule
__init__.py
testMod.py
main.py
Run Code Online (Sandbox Code Playgroud)
testMod.py文件:
def test(n):
print "echo"+n
Run Code Online (Sandbox Code Playgroud)
main.py文件:
import testModule
testModule.test(4)
Run Code Online (Sandbox Code Playgroud)
当我尝试在PyDev中运行它时,它在main.py,第2行(其中调用test(4))时给了我这个错误:
AttributeError: 'module' object has no attribute 'test'
Run Code Online (Sandbox Code Playgroud)
我将main.py更改为:
import testModule.test
testModule.test(4)
Run Code Online (Sandbox Code Playgroud)
仍然给我错误 'module' object not callable!
这有什么问题?
你错过了这个testMod
模块.您的方法的全名是testModule.testMod.test
.