Can I use MySQLdb.Connection with an instruction with an object?

I wonder if I can use the with context manager with Connection object and write code like this:

 with MySQLdb.connect(...) as conn: do_something() 

Will the conn object close automatically after a block like the file object?

Thanks.

+5
source share
1 answer

MySQLdb does not support the context manager protocol. Roll your own or use oursql instead.

+3
source

All Articles