小编Sim*_*ght的帖子

For Loop或executemany - Python和SQLite3

我最近开始学习Python和SQL并且有一个问题.

使用Python和SQLite3我编写了以下代码:

# Use sqlite3 in the file
import sqlite3

# Create people.db if it doesn't exist or connect to it if it does exist
with sqlite3.connect("people.db") as connection:
    c = connection.cursor()

    # Create new table called people
    c.execute("""CREATE TABLE IF NOT EXISTS people(firstname TEXT, lastname TEXT, age INT, occupation TEXT)""")


    people_list = [
        ('Simon', 'Doe', 20, 'Python Master'),
        ('John', 'Doe', 50, 'Java Master'),
        ('Jane', 'Doe', 30, 'C++ Master'),
        ('Smelly', 'Doe', 2, 'Shower Master')
    ]

    # Insert dummy data into …
Run Code Online (Sandbox Code Playgroud)

python sql sqlite for-loop executemany

6
推荐指数
1
解决办法
4888
查看次数

标签 统计

executemany ×1

for-loop ×1

python ×1

sql ×1

sqlite ×1