我的元组看起来像这样:
Enter the name of the employee: Joe
Enter the ID number of the employee: 5555
Enter 1 if they work day shift or 2 if they work night shift: 2
Enter how much they make hourly (numerical): 30
The employee's name is Bob. Bob's ID number is: 001121. They work on the night shift and make $30.00 an hour.
如果我有一个有两列的表,我可以这样做:
test_tuple = ((1,2),(2,2),(3,5))
现在,如果我想插入三列,第三列是Python的变量,我该如何实现呢?
executemany("insert into mytable (col1, col2) values (?, ?);", test_tuple)
表中的结果:
ran_string_var = 'foo'
executemany("insert into mytable (col1, col2, col3) values (?, ?, ran_string_var);", test_tuple)
我有哪些选择?也许将我想要的变量添加到元组中?
我不能用引号硬编码字符串,因为它是动态的。