import sqlite3con = sqlite3.connect(":memory:")columns = ["Nom", "Age", "Taille"]columns_str = '"' + '","'.join(columns) + '"'con.execute(f"CREATE TABLE people ({columns_str})")data = [ ('Karl', 11, 185)]stmt = f"INSERT INTO people ({columns_str}) VALUES (?, ?, ?)"con.executemany(stmt, data)另外,可能不要打电话给你的桌子master——稍后会变得非常混乱。L像和 之类的名字list2也没有帮助。明确命名变量,按照它们的含义或包含的内容命名。未来的你会感谢你的。也许更干净一点:import sqlite3con = sqlite3.connect(":memory:")columns = ("Nom", "Age", "Taille")con.execute("CREATE TABLE people (%s, %s, %s)" % columns)data = [ ('Karl', 11, 185)]stmt = f"INSERT INTO people (%s, %s, %s) VALUES (?, ?, ?)" % columnscon.executemany(stmt, data)
1 回答
米琪卡哇伊
TA贡献1998条经验 获得超6个赞
这是一种方法:
import re
...
def normalize(data):
#converting all letters to lowercase
lowercase_lines=[x.lower() for x in data]
# strip out all non-word or tab or space characters
stripped_lines = [re.sub(r"[^\w \t]+", "", x) for x in lowercase_lines]
print(stripped_lines)
return stripped_lines
添加回答
举报
0/150
提交
取消