python - 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'。
不知道我做错了什么,任何帮助表示赞赏。
谢谢
解决方案
推荐阅读
- python - Django REST Framework:网站开发完成后可以实现吗?
- python - 如何挂载 Docker 容器卷
- android - 到目前为止一切正常时,为什么我的 Android 应用程序运行两个实例?
- arrays - Array.map() 和 Array.forEach() 返回原始数组
- angular - angular-mdl 是否与 SSR angular Universal 一起使用
- assembly - 如何在 VASM Z80 组件中为 32K MSX-1 墨盒进行 ROM 墨盒存储?
- jenkins - 如何在 src 中导入记录器模块并在所有 groovy 脚本中使用它?
- javascript - 尝试对我的表单进行实时计算时,我的总变量出现未定义变量错误
- http - Flutter http异常'(HttpException)=> Null'不是类型'(动态)=>动态'的子类型
- mysql - PHPMyAdmin Configuration not working because of MySQL user password?