导入其他 python 文件时 python 中没有属性错误

no attribute error in python while importing other python file

我在当前 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.

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

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

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

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

abc.py文件改成另一个名字,它是一个标准库。