在Python中,self是一个对实例对象本身的引用,用于访问属于该类的变量和方法。当你在类中定义一个方法时,该方法的第一个参数总是表示调用该方法的对象本身,按照惯例,这个参数被命名为self。通过self,可以访问类的属性和其他方法。 2. 分析导致“missing 1 required positional argument: 'self'”错误的原因 这个错误...
调用类方法时报错:missing 1 required positional argument: 'self' 这种情况是因为在调用方法时,没有提前定义这个类的实例,导致无法返回。只要先定义一个实例就可以了
问题场景:封装requests的时候写了一个类,然后请求的时候接口报TypeError: send_request() missing 1 required positional argument: 'self' 首先封装的代码是这样的,如下图 请求的代码如下图 执行后报错 解决办法,通过对象调用
classDelft:def__init__(self, name):self.name = namedeffun(self):returnself.name m = Delft a = m.fun()print(a) 输出: 现在让我们在下面的部分中讨论如何修复此错误。 修复Python 中的 TypeError: missing 1 required positional argument: 'self' 错误 要修复此错误,我们可以创建类实例并使用它来访...
The Python TypeError: missing 1 required positional argument: 'self' occurs when we call a method on the class instead of on an instance of the class.
Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: main() missing 1 required positional argument: 'self' FYI: I have added the module.pakage:class.function in pyproject.toml as shown below. `[tool.poetry.scripts] findata = "investment.ParseFinData:Cal...
RT,在创建模型对象的时候,提示TypeError: save() missing 1 required positional argument: 'self' 解决办法:在创建模型对象的时候需要加上() 例如:from .models import userinfo usr = userinfo #错误 usr = userinfo() #正确 PS:别忘了在创建完数据后进行数据表生成和迁移的操作...
TypeError: seperate_data() missing 1 required positional argument:'self' 报错原因: train_data, test_data = DataCleaner.seperate_data() DataCleaner 是个类,seperate_data() 是其中的方法,不能直接这样调用,需要先将类实例化。 代码改为: train_data, test_data = DataCleaner().seperate_data() ...
missing 1 required positional argument: ‘self’ Positional arguments refer to data that is passed into a function. In a class, every function must be given the value “self”. The value of “self” is similar to “this” in JavaScript. “self” represents the data stored in an object of...
然后我又创建了一个新的python文件。里面的方法需要引用刚刚那个helper类的方法 调用之前我实例化了这个helper类。接着问题就出现在这里 对象的声明需要括号。而类的声明括号可有可无。 定义在自定义类中的方法需要一个默认的self参数。错误提示没有self 就是说明这个类的对象没有创建成功...