English 中文(简体)
假设:提供的参数太多
原标题:python: too many parameters provided

谁能解释一下什么错误? 我是否做了一些错误?

>>> class qw: 
...     def f2x(par1, par2, par3): 
...             print par1, par2, par3 
...
>>> obj = qw()
>>> obj.f2x("123", 13, "wert") Traceback (most recent call last):  
File "<stdin>", line 1, in <module>
TypeError: f2x() takes exactly 3 arguments (4 given)
>>>

如果我只界定一项职能,那么它就将所有工作罚款计算在内。

>>> def f2x(par1, par2, par3):
...     print par1, par2, par3
... 
>>> f2x("1", 2, "too many")
1 2 too many
>>>
最佳回答

I guess its because of every method of a python class object implicitly has a first paramter which points to the object itself.

审判

def f2x(self, par1, par2, par3):

you still call it with your 3 custom parameters

>>> class qw:
...     def f2x(self, p1, p2, p3):
...             print p1,p2,p3
... 
>>> o = qw()
>>> o.f2x(1,2,3)
1 2 3
问题回答

您认为,所有成员的职能都间接地得到另一个论点,即《公约》中称作<条码>。

Try:

class qw:
  def f2x(self, par1, par2, par3):
    print par1, par2, par3

But still call it as before:

obj = qw()
obj.f2x("123", 13, "wert")

f2x上, per 是成员被点名的物体。 这是一种非常根本的概念,你应该真正了解这一点。

您的班级方法定义中的<代码>自封/编码>参数:

class qw:
    def f2x(self, par1, par2, par3):
        print par1, par2, par3

我建议通过一部启蒙书/辅导。 standard tutorial 选择好,特别是如果你已经掌握了另一种语言的经验的话。

接着,请你说:

g = qw()
g.f2x( 1 ,  2 ,  3 )




相关问题
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 ]="...

热门标签