代码如下:
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'
__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()
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
应该这样写
import pymysql
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()
__init__
写成__int__
了有帮助望采纳~