【问题标题】:no attribute error in python while importing other python file导入其他python文件时python中没有属性错误
【发布时间】:2020-08-08 18:26:42
【问题描述】:

我在我当前的 python 文件中导入了另一个 python 文件。当我从导入的 python 文件调用函数时,它显示Attribute Error: module 'abc' has no attribute 'classify'。如何解决这个问题?

app.py

import abc
a=abc.classify(upload)

abc.py

def classify(data):
  app.logger.debug('Running classifier')
  upload = data
  image = load_image(upload)
  #load_image() is to process image :
  print('image ready')

请告诉我这里出了什么问题。我使用 python 版本 3.7.4。

【问题讨论】:

    标签: python import attributeerror


    【解决方案1】:

    这是因为'abc'是一个python标准库

    https://docs.python.org/3/library/abc.html

    所以当你用import abc 导入它时,你实际上是在导入标准的,而不是你自己的模块。因此,要么为它选择另一个名称,要么进行相对导入;如果它与您的其他文件位于同一路径级别,您可以执行import .abc

    但我建议您选择其他名称以避免进一步的问题

    【讨论】:

      【解决方案2】:

      abc.py 文件更改为另一个名称,它是一个标准库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-09
        • 2019-10-09
        • 2019-05-19
        • 2016-05-01
        • 2021-10-04
        • 2022-01-22
        相关资源
        最近更新 更多