24.1 >>> import sqlite3 >>> conn = sqlite3.connect("datafile") >>> cursor = conn.cursor() >>> cursor.execute("create table test (name text, count integer)") >>> cursor.execute("insert into test (name, count) values ('Bob', 1)") >>> cursor.execute("insert into test (name, count) values (?, ?)", ("Jill", 15)) >>> cursor.execute("insert into test (name, count) values (:username, \ :usercount)", {"username":"Joe", "usercount":10}) >>> result = cursor.execute("select * from test") >>> print(result.fetchall()) [('Bob', 1), ('Jill', 15), ('Joe', 10)] >>> result = cursor.execute("select * from test where name like :name", {"name":"bob"}) >>> print (result.fetchall()) [('Bob', 1)] >>> cursor.execute("update test set count=? where name=?", (20, "Jill")) >>> result = cursor.execute("select * from test") >>> print(result.fetchall()) [('Bob', 1), ('Jill', 20), ('Joe', 10)] >>> result = cursor.execute("select * from test") >>> for row in result: ... print(row) ... ('Bob', 1) ('Jill', 20) ('Joe', 10) >>> cursor.execute("update test set count=? where name=?", (20, "Jill")) >>> conn.commit() >>> conn.close() 24.2.1 >>> from http.server import HTTPServer, SimpleHTTPRequestHandler >>> server = HTTPServer(("",8000), SimpleHTTPRequestHandler) >>> server.serve_forever() 24.2.2 Writing an HTTP client >>> from urllib.request import urlopen >>> url_file = urlopen("http://localhost:8000") >>> print(url_file.geturl() http://localhost:8000 >>> print(url_file.info()) Server: SimpleHTTP/0.6 Python/3.1a1+ Date: Sat, 06 Nov 2009 20:28:13 GMT Content-type: text/html; charset=utf-8 Content-Length: 15395 >>> for line in url_file.readlines(): ... print(line) ... b'\n' b'