首页 > 解决方案 > Python - 模块没有属性

问题描述

我正在将我的长单个 python 脚本拆分为多个文件/模块。在这样做的过程中,我遇到了以下问题。我不确定我是否在语法上做错了什么,或者只是基本逻辑是错误的。

我当前的文件夹结构如下

parentFolder
    folA
        __init__.py
        fileA.py
        fileB.py
    app.py

文件B.py

def test():
    print("Hello from fileB")

文件A.py

import fileB
def run():
    fileB.test()
    print("Hello from fileA")

应用程序.py

from folA import fileA
fileA.run()

我收到错误“AttributeError:模块'fileB'没有属性'test'。

不知道我做错了什么,任何帮助表示赞赏。

谢谢

标签: pythonattributeerror

解决方案


推荐阅读