Last active
July 25, 2016 06:52
-
-
Save kurozumi/d8219986c13f5d18a40c4a11e7dc4dd7 to your computer and use it in GitHub Desktop.
【Python】MySQL Connectorをwith構文を使えるようにする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Connector(object): | |
def __init__(self, account): | |
self.account = account | |
def __enter__(self): | |
import mysql.connector | |
self.connect = mysql.connector.connect( | |
db = self.account["db"], | |
host = self.account["host"], | |
user = self.account["user"], | |
passwd = self.account["passwd"], | |
charset = "utf8") | |
return self.connect | |
def __exit__(self, exception_type, exception_value, traceback): | |
self.connect.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment