Can I use with statement with MySQLdb.Connection object?

Viewed 6685

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

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

Will the conn object be closed automatically after the block like with a file object ?

Thanks.

1 Answers
Related