-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlh.py
More file actions
41 lines (31 loc) · 1.01 KB
/
sqlh.py
File metadata and controls
41 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# create a table and populate it
import sqlite3
with sqlite3.connect("new.db") as connection:
c = connection.cursor()
c.execute("""CREATE TABLE regions
(city TEXT, region TEXT)
""")
cities = [
('New York City', 'Northeast'),
('San Francisco', 'West'),
('Chicago', 'Midwest'),
('Houston', 'South'),
('Phoenix', 'West'),
('Boston', 'Northeast'),
('Los Angeles', 'West'),
('Houston', 'South'),
('Philadelphia', 'Northeast'),
('San Antonio', 'South'),
('San Diego', 'West'),
('Dallas', 'South'),
('San Jose', 'West'),
('Jacksonville', 'South'),
('Indianapolis', 'Midwest'),
('Austin', 'South'),
('Detroit', 'Midwest')
]
c.executemany("INSERT INTO regions VALUES(?,?)",cities)
c.execute("SELECT * FROM regions ORDER BY region ASC")
rows = c.fetchall()
for r in rows:
print r[0], r[1]