【问题标题】:how to create a utils.py module如何创建 utils.py 模块
【发布时间】:2021-12-30 05:49:37
【问题描述】:

我的home/file.py 中有一个def hello() 函数。我创建了一个home/common/utils.pyfile 并将函数移到那里。 然后我像这样导入它:from utils import hello 并且我的文件中的导入不会引发错误。

该路径也自动添加到我的 settings.json 中:

  "python.analysis.extraPaths": [
    "home/common"
  ]

但是,当我运行代码时,它显示Runtime.ImportModuleError: Unable to import module 'file': No module named 'utils'

那么创建 utils 模块的正确方法是什么?

【问题讨论】:

  • 您现在导入的文件是什么?您的模块目录结构如何?你如何执行代码?你执行哪个模块?
  • 我在home/file.py 中进行导入。我在home/common/utils.py 中创建了另一个文件夹。我在 aws lambda 中执行代码(file.py)。 @DariuszKrynicki

标签: python python-3.x file import fileutils


【解决方案1】:

在file.py中:

从 common.utils 导入你好

【讨论】:

猜你喜欢
  • 2021-12-30
  • 1970-01-01
  • 2016-06-23
  • 2010-10-07
  • 2018-05-04
  • 2021-06-26
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多