開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Head First Python 第2版 ―頭とからだで覚えるPythonの基本 (Paul Barry (著)、嶋田 健志 (監修)、木下 哲也 (翻訳)、オライリージャパン)の9章(コンテキストマネジメントプロトコル - with文を使う)、自分で考えてみよう(p. 341)を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
class UseDatabase:
def __init__(self, dbconfig: dict) -> None:
self.dbconfig = dbconfig
def __enter__(self):
pass
def __exit__(self, *args):
pass
if __name__ == '__main__':
dbconfig = {'host': 'localhost',
'database': 'vsearchlogDB'}
with UseDatabase(dbconfig) as db:
print(db)
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ ./sample1.py None $
0 コメント:
コメントを投稿