Function()只需要2个参数(给定3个)

vai*_*hav 16 python

我正在使用python来调用一个类中的方法,该类位于另一个其他类文件中的方法的一个文件中

假设我的文件abc.py包含

class data : 

         def values_to_insert(a,b):
               ......
                ......
Run Code Online (Sandbox Code Playgroud)

另一个文件是 def.py

import abc
class values:
      data=abc.data()
      def sendvalues():
          a=2
          b=3
          data.values(a,b)
Run Code Online (Sandbox Code Playgroud)

当我运行此文件时,它会出错: values() takes exactly 2 arguments (3 given)

Mik*_*ert 23

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

def values_to_insert(self, a, b):
Run Code Online (Sandbox Code Playgroud)

你可以在这里阅读有关这个​​的原因.