当前位置:网站首页>错误记录: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的提示中是都有这两种的,而且问题还不好查找
边栏推荐
猜你喜欢

A semi-supervised Laplace skyhawk optimization depth nuclear extreme learning machine for classification

MAML原理讲解和代码实现

Base64编码原理

Faster - RCNN principle and repetition code

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

MMDeploy部署实战系列【第四章】:onnx,tensorrt模型推理

西门子PLC1200与fanuc机器人进行profibus通讯

Software: Recommend a domestic and very easy-to-use efficiency software uTools to everyone

基于时序模式注意力机制(TPA)的长短时记忆(LSTM)网络TPA-LSTM的多变量输入风电功率预测

Activiti 工作流引擎 详解
随机推荐
matlab的2DCNN、1DCNN、BP、SVM故障诊断与结果可视化
西门子PLC1200与fanuc机器人进行profibus通讯
“需求370解决解决爬取章节之后主题讨论评论消失问题”工作总结
数据库文档生成工具V1.0
ubuntu18.04安装redis教程
设置el-table自动向下滑动(不多解释,直接代码实现)
Faster RCNN原理及复现代码
基于EEMD+GRU+MLR的时间序列预测
Software: Recommend a domestic and very easy-to-use efficiency software uTools to everyone
专题讲座7 计算几何 学习心得
硬件知识:RTMP和RTSP传统流媒体协议介绍
无监督特征对齐的迁移学习理论框架
FCN——语义分割的开山鼻祖(基于tf-Kersa复现代码)
A semi-supervised Laplace skyhawk optimization depth nuclear extreme learning machine for classification
【深度学习实践(二)】上手手写数字识别
Computer software: recommend a disk space analysis tool - WizTree
MATLAB版量化交易技术分析工具TA-Lib【不付费也可获取,不要被付费吓跑】
MySQL重置root密码
用matlab打造的摩斯电码加解码器音频版,支持包括中文在内的任意字符
mysql:列类型之float、double