运行以下代码出现的问题:%d format: a number is required, not str。
username = input("请输入用户名: ")
password = input("请输入密码: ")
password = hashlib.md5(password.encode("utf-8")).hexdigest()
real_name = input("请输入真实姓名: ")
tel = input("请输入电话: ")
birth = input("请输入生日: ")
email = input("请输入邮件: ")
sex = input("请输入性别: ")
avatar = ""
state = int(input("请输入状态: "))
create_time = "2024-10-22"
update_time = "2024-10-22"
delet = int(input("请输入删除标志: "))
sql ="INSERT INTO tb_user (username, password, real_name, tel, birth, email, sex, avatar, state, create_time, update_time, delet) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %d)"
mysqlUtil = MySqlUtil()
args = (username, password, real_name, tel, birth, email, sex, avatar, state, create_time, update_time, delet)
result = mysqlUtil.operator_data(sql, args)
print(result)
解决办法: 把%d改成%s,必须全部使用%s
原因:MySQLdb的字符串格式化不是标准的python的字符串格式化,应当一直使用%s用于字符串格式化。
总结一下吧自己查了一个小时,然后找到的原因 很不容易 心累。。。
原文参考:%d format: a number is required, not str。-CSDN博客
标签:real,格式化,pyMysql,插入,time,input,password,输入 From: https://blog.csdn.net/m0_64192871/article/details/140532313