AttributeError在尝试访问python函数时出错

AttributeError在尝试访问python函数时出错,python,python-module,Python,Python Module,我试图将一个类的python函数访问到另一个脚本中。这给了我以下错误: AttributeError: 'module' object has no attribute 'functionName' 该函数存在于类中,可通过classname.functionName()调用进行访问。 有什么我遗漏的吗 -更新- 我的代码是: (program.py) import ImageUtils import ... class MyFrame(wx.Frame): ... ImageUtil

我试图将一个类的python函数访问到另一个脚本中。这给了我以下错误:

AttributeError: 'module' object has no attribute 'functionName'
该函数存在于类中,可通过classname.functionName()调用进行访问。 有什么我遗漏的吗

-更新-

我的代码是:

(program.py)
import ImageUtils
import ...
class MyFrame(wx.Frame):
...
    ImageUtils.ProcessInformation(event)


(ImageUtils.py)
import statements... 
class ImageUtils(threading.Thread):
    def ProcessInformation(self, event):
        self.queue.put(event)
因此,错误是:AttributeError:“module”对象没有属性“ProcessInformation”
那么,我是否必须使第二个脚本仅成为模块?

可能您试图从模块而不是从类调用函数。我建议你做一些类似的事情:

from my_module import my_class

my_class.my_function(...)
# bla bla bla

编辑:我认为Python不允许在函数名中使用“-”。

类中的函数称为方法。您可以使用从其他模块访问它

import module
module.Classname.method
但是,除非该方法是调用staticmethod或classmethod的特殊方法, 您将无法使用
module.Classname.method()
调用它

相反,您需要创建该类的实例:

inst=module.Classname(...)
然后从类实例调用该方法:

inst.method()

您收到错误的原因

AttributeError: 'module' object has no attribute 'function_name'
是因为
模块
的命名空间中没有名为
函数_name
的变量。但是,它确实有一个名为
Classname
的变量。 同时,
Classname
在其名称空间中有一个名为
function\u name
的变量。 因此,要访问该方法,您需要通过执行两个属性查找来“深入”到
函数\u名称
:module.Classname.function\u名称,您可能需要尝试该函数,以查看函数是否如您所期望的那样实际存在

使用
数学
模块的示例:

>>> import math
>>> dir(math)
['__doc__', '__file__', '__name__', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'cosh', 'degrees', 'e', 'exp', 'fabs', 'floor', 'fmod', 'frexp', 'hypot', 'ldexp', 'log', 'log10', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh']

你能发布你的代码吗?也许是引发错误的代码片段?以及模块的导入语句,因为在导入步骤中可能会出现错误。请在此处添加更多信息,好吗?与列表导入、文件树等类似?
函数名
不是有效的标识符。我假设这只是匿名化的结果,但这仍然是不必要的混淆。你是指我的_类。我的_函数()谢谢,但作为一个类的使用,这是不可能的。尽管如此,我还是尝试过,但如果没有模块化,这种方法会失败。我尝试在这里创建一个静态方法,并使用工厂模式访问它