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

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日

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置