This question already has an answer here:
这个问题已经有了答案:
- Why accessing to class variable from within the class needs “self.” in Python? [duplicate] 4 answers
- 为什么从类内部访问类变量需要“self”。“在Python中?(重复)4的答案
- What is the purpose of self? 18 answers
- 自我的目的是什么?18个答案
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.py
that 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()恰好取2个参数(给定3个参数)
1 个解决方案
#1
19
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.
你可以在这里读到它的原因。
#1
19
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.
你可以在这里读到它的原因。