English 中文(简体)
试图获得假肢功能的副手
原标题:AttributeError in trying to access a python function

我正试图将一个班级的假 function功能进入另一个文字。 这使我有以下错误:

AttributeError:  module  object has no attribute  functionName 

The function is present in a class and is accessed via classname.functionName() call. Is there anything that I am missing ?

- 更新

我的法典是:

(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)

Thus, the error is : AttributeError: module object has no attribute ProcessInformation So, do I have to make this second script a module only ?

问题回答

课堂内的功能称为一种方法。 你们可以从另一个单元进入。

import module
module.Classname.method

However, unless that method is a special kind of method call a staticmethod or classmethod, you won t be able to call it with module.Classname.method().

相反,你需要证明:

inst=module.Classname(...)

之后将这种方法从班级改为:

inst.method()

您收到错误的原因

AttributeError:  module  object has no attribute  function_name 

is because module does not have a variable named function_name in its namespace. It does have a variable named Classname however. Meanwhile, Classname has a variable named function_name in its namespace. So to access the method, you need to "burrow down" to function_name by performing two attribute lookups: module.Classname.function_name.

可以证明,你试图将这一功能从单元中而不是从该类别中调取。 我建议你做这样的事情:

from my_module import my_class

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

http://www.un.org。 我认为,“沙尔”不会让你以职能的名义使用“-”。

您不妨尝试dir(,以便了解该职能是否与你预期的实际存在。

缩略语 模块:

>>> 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 ]




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签