gpt4 book ai didi

python - 无法在 Python 中访问导入的函数

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:09 24 4
gpt4 key购买 nike

谁能帮我解决这个问题?

我正在继续使用 PyDev Aptana 开发 Python 代码。这是我在 PyDev IDE 下的项目结构:

/testProject
/src
/testModule
__init__.py
testMod.py
main.py

testMod.py 文件:

def test(n): 
print "echo"+n

main.py 文件:

import testModule
testModule.test(4)

当我尝试在 PyDev 中运行它时,它在 main.py 的第 2 行(调用 test(4) 的地方)给我这个错误:

AttributeError: 'module' object has no attribute 'test'

我将 main.py 更改为:

import testModule.test
testModule.test(4)

仍然给我错误 'module' object not callable!

这是怎么回事??

最佳答案

您错过了 testMod 模块。您的方法的全名是 testModule.testMod.test

关于python - 无法在 Python 中访问导入的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6877745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com