5
我不知道我是否可以使用上下文管理with
與Connection
對象,並寫出這樣的代碼:我可以使用帶有MySQLdb.Connection對象的語句嗎?
with MySQLdb.connect(...) as conn:
do_something()
請問conn
對象像一個file
對象塊後自動關閉?
謝謝。
我不知道我是否可以使用上下文管理with
與Connection
對象,並寫出這樣的代碼:我可以使用帶有MySQLdb.Connection對象的語句嗎?
with MySQLdb.connect(...) as conn:
do_something()
請問conn
對象像一個file
對象塊後自動關閉?
謝謝。
MySQLdb不支持上下文管理器協議。 Roll your own, or use oursql instead.
您是否要求提問者支付賞金2在另一個問題中爲他寫代碼,還是我誤解了它? – TankorSmash 2012-08-01 02:43:33
@TankorSmash:不是特別的賞金;我也接受PayPal轉賬和亞馬遜加拿大禮品券。 – 2012-08-01 02:45:01
嗯,我想每個人都需要以某種方式謀生。 – TankorSmash 2012-08-01 02:53:36