開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 9(Manage Your data: Handling input)、EXERCISE(p.335)を解いてみる。
EXERCISE(p.335)
コード(BBEdit, Emacs)
sample335.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- import sqlite3 db_name = 'coachdata.sqlite' def get_namesID_from_store(): connection = sqlite3.connect(db_name) cursor = connection.cursor() result = cursor.execute("""SELECT name, id FROM athletes""") response = cursor.fetchall() connection.close() return response if __name__ == '__main__': print(get_namesID_from_store())
入出力結果(Terminal, IPython)
$ ./sample335.py [('Sarah Sweeney', 1), ('Mikey McManus', 2), ('Sally Sanchez', 3), ('Vera Vi', 4), ('Julie Jones', 5), ('James Lee', 6)] $
0 コメント:
コメントを投稿