当前位置:网站首页>错误记录:TypeError: object() takes no parameters
错误记录:TypeError: object() takes no parameters
2022-08-04 05:56:00 【LCY133】
一个很简单的定义类和进行实例化的例子
# 创建和使用类
class Dog1:
# 定义一个类
def __int__(self,name,age): # 注意,初始化时不要把init写成int,这样会导致在实例化时显示没有参数
self.name = name
self.age = age
print('init is running')
def sit(self):
print(self.name,'is now sitting')
def roll_over(self):
print(self.name,'is now rolling')
my_dog = Dog1('blue',10)
my_dog.sit()
在运行时出现问题:
Traceback (most recent call last):
File "E:/Python_code/0.review/lesson1/class_test.py", line 20, in <module>
my_dog = Dog1('blue',10)
TypeError: object() takes no parameters
其实问题的原因在于,写__init__方法时写成了__int__,在这里很容易写错的,因为pycharm的提示中是都有这两种的,而且问题还不好查找
边栏推荐
猜你喜欢

ThreadLocal内存泄漏问题讲解

A priori box (Anchor) in target detection

Provide 和 Inject 的用法

拒绝碰运气,导师人品这样了解!

无监督特征对齐的迁移学习理论框架

如何用matlab做高精度计算?【第三辑】(完)

Database: Organize Four Practical SQL Server Scripting Functions

Based on the EEMD + + MLR GRU helped time series prediction

NelSon:一款新的适配matlab编程语法的编程工具

Microsoft computer butler 2.0 beta experience
随机推荐
DropBlock: 卷积层的正则化方法及复现代码
Promise.all 使用方法
Gramm Angle field GAF time-series data into the image and applied to the fault diagnosis
更改mysql数据库默认的字符集(mysql 存储 emoji表情)
A priori box (Anchor) in target detection
YOLOv3详解:从零开始搭建YOLOv3网络
90多款matlab工具箱打包放送
Activiti 工作流引擎 详解
Online public account article content to audio file practical gadget
从零开始单相在线式不间断电源(UPS)(硬件)
电脑知识:台式电脑应该选择品牌和组装,值得收藏
缓动动画,有关窗口的一些常见操作,BOM操作
子空间结构保持的多层极限学习机自编码器(ML-SELM-AE)
ThreadLocal内存泄漏问题讲解
Error EPERM operation not permitted, mkdir ‘Dsoftwarenodejsnode_cache_cacach两种解决办法
手把手教你Charles抓包工具使用
数据库技巧:整理SQLServer非常实用的脚本
matlab的2DCNN、1DCNN、BP、SVM故障诊断与结果可视化
SENet detailed explanation and Keras reproduction code
Faster - RCNN principle and repetition code