Python Function() 正好接受 2 个参数(给出 3 个)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17874744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:23:36  来源:igfitidea点击:

Function() takes exactly 2 arguments (3 given)

python

提问by vaibhav

I am using python to call a method in one class that is in one file from a method in another class of other file

我正在使用 python 从其他文件的另一类中的方法调用一个文件中的一个类中的方法

Suppose my file is abc.pythat contains

假设我的文件abc.py包含

class data : 

         def values_to_insert(a,b):
               ......
                ......

another file is def.py

另一个文件是 def.py

import abc
class values:
      data=abc.data()
      def sendvalues():
          a=2
          b=3
          data.values(a,b)

When I run this file it gives an error: values() takes exactly 2 arguments (3 given)

当我运行这个文件时,它给出了一个错误: values() takes exactly 2 arguments (3 given)

采纳答案by Miklos Aubert

If it's in a class, your method should be :

如果它在一个类中,你的方法应该是:

def values_to_insert(self, a, b):

You can read about the reasoning for this here.

您可以在此处阅读其原因。