![](/img/trans.png)
[英]Why could flask fail at serving one file from a static directory but succeeds at serving another one from the same directory
[英]import succeeds for one file but not another in the same directory
我有一个名为proja的项目文件夹。 它包含几个文件:
"__init__.py"
classa.py
classb.py
classc.py
我在proja中有一个名为folderb的子文件夹。 它也有一个“” init .py“”。 此文件夹包含带有以下导入语句的py脚本。 它导入classa,但在classb上失败。
from classa import classa
from classb import classb
from class import classc
不管是从proja运行脚本:“ python folderb / imptest.py”,还是从cd到cd并运行:“ python imptest.py”。
它总是失败并显示:“ ImportError:没有名为classb ...的模块”
为什么要从一个文件而不是同一位置的另一个文件导入?
确保文件classb.py
有一个名为classb
的函数或方法
使用以下命令运行文件:
import classa
import classb
import classc
如果此命令有效,则文件路径正常,您应该查看文件内部。
如果执行此操作并且可以正常工作,请检查文件classb.py
的内部,
否则发布错误。 我会帮你的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.