我尝试使用方法“insert_users”向数据库表添加一些信息。与变量 self.tests2 连接到 INSERT 查询相关的问题,当我尝试这样做时,我有:TypeError:并非所有参数都在字符串格式化期间转换。当我尝试插入而不是 'self.test2' 字符串 '%s','%s','%s','%s','%s','%s','%s','% s'所有的作品。什么事?
def insert_users(self, users_dict, rows_names):
self.test1 = len(rows_names) * ["%s"]
print self.test1
self.test2 = "'" + "','".join(self.test1) + "'"
self.cursor = self.connection.cursor()
for name, val in users_tuple.items():
self.cursor.execute("""INSERT INTO users(""" + \
",".join(rows_names) + """) VALUES(""" + **self.test2** + """)""" %\
(name, val, 'SomeNickname', 'password', '13-09-11', '2', '@gmail.com','1'))
ConnectToDb.connection_cot_cle(self)
users_dict = {'FirstName':'LastName'}
rows_names = ('Fname', 'Lname', 'login', 'password','reg_date', 'role_id',\
'email', 'is_active')
db_instans.insert_users(users_dict, rows_names)