clare471 2022-01-03 23:38 采纳率: 66.7%
浏览 94
已结题

python创建类,调用类方法时老显示没传进去参数

代码如下:

class Update:
    def __int__(self, table, key, header, date):
        self.table = table
        self.key = key
        self.date = date
        self.header = header
    def update_date(self):
        conn = pymysql.connect(host="localhost", port=3306, user="root", password="123456", charset="utf8",
                       db="冀熙科技管理系统")
        cursor = conn.cursor()
        sql = '''update {0} set {1}='{2}' where id='{3}';'''.format(self.table, self.header, self.date, self.key)
        cursor.execute(sql)
        conn.commit()
        cursor.close()
        conn.close()
a = Update
a.update_date(table='project_information', key='202101', header='step', date='关门')

错误显示为:update_date() got an unexpected keyword argument 'table'

  • 写回答

3条回答 默认 最新

  • 关注
    __int__ 改成 __init__
    
    a = Update
    a.update_date(table='project_information', key='202101', header='step', date='关门')
    改成
    a = Update(table='project_information', key='202101', header='step', date='关门')
    a.update_date()
    

    你题目的解答代码如下:

    class Update:
        def __init__(self, table, key, header, date):
            self.table = table
            self.key = key
            self.date = date
            self.header = header
        def update_date(self):
            conn = pymysql.connect(host="localhost", port=3306, user="root", password="123456", charset="utf8",
                           db="冀熙科技管理系统")
            cursor = conn.cursor()
            sql = '''update {0} set {1}='{2}' where id='{3}';'''.format(self.table, self.header, self.date, self.key)
            cursor.execute(sql)
            conn.commit()
            cursor.close()
            conn.close()
    
    
    a = Update(table='project_information', key='202101', header='step', date='关门')
    a.update_date()
    
    

    如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 专家修改了标签 1月24日
  • 系统已结题 1月12日
  • 已采纳回答 1月4日
  • 创建了问题 1月3日

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格