【问题标题】:Unable to import another file from same workspace无法从同一工作区导入另一个文件
【发布时间】:2020-11-02 06:37:02
【问题描述】:

我是 Visual Studio 代码的新手。目前面临如下所示的问题,即出现错误,我无法从同一个工作区(但另一个文件夹)导入我的代码。虽然我对 python 也很陌生,但我很确定我使用的代码是正确的。

from business.request_process import *

如果有人知道发生了什么问题以及如何解决问题,将不胜感激。谢谢!

photo of my workspace + code + error

【问题讨论】:

  • 试试Practical5.business.request_process import *

标签: python visual-studio visual-studio-code


【解决方案1】:

这是因为你的request_io.py在目录presentation中,并且里面没有名为“business”的目录。

您可以在系统路径中附加您要导入的任何目录,您的代码应该是这样的

import sys
sys.path.append('path_to_your_workspace/Practical5/business')
from request_process import *

或者将request_io.py移动到它可以看到business的地方(在这种情况下是实用的5)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    相关资源
    最近更新 更多