開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 9.(The Context Management Protocol: Hooking Into Python's With Statement) の SHARPEN YOUR PENCIL(No. 6492) を取り組んでみる。
Relational Database は MySQL、MariaDBの代わりに SQLite を使用。
SHARPEN YOUR PENCIL(No. 6492)
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sqlite3
class UseDatabase:
def __init__(self, dbconfig: dict) -> None:
self.dbconfig = dbconfig
def __enter__(self):
pass
def __exit__(self):
pass
if __name__ == '__main__':
dbconfig = {'host': '127.0.0.1',
'user': 'vsearch',
'password': 'vsearchpasswd',
'database': 'vsearchlogDB'}
ud = UseDatabase(dbconfig)
print(ud.dbconfig)
入出力結果(Terminal, IPython)
$ ./DBcm.py
{'host': '127.0.0.1', 'user': 'vsearch', 'password': 'vsearchpasswd', 'database': 'vsearchlogDB'}
$
0 コメント:
コメントを投稿