Re: Context manager for database connection

2023-08-23 Thread dn via Python-list
On 24/08/2023 03.41, Jason Friedman via Python-list wrote: I want to be able to write code like this: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor()

Re: Getty fully qualified class name from class object

2023-08-23 Thread Ian Pilcher via Python-list
On 8/22/23 11:13, Greg Ewing via Python-list wrote: Classes have a __module__ attribute: >>> logging.Handler.__module__ 'logging' Not sure why I didn't think to look for such a thing. Looks like it's as simple as f'{cls.__module__}.{cls.__qualname__}'. Thanks! --

Re: Context manager for database connection

2023-08-23 Thread dn via Python-list
On 24/08/2023 06.11, dn via Python-list wrote: On 24/08/2023 03.41, Jason Friedman via Python-list wrote: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor()

Context manager for database connection

2023-08-23 Thread Jason Friedman via Python-list
I want to be able to write code like this: with Database() as mydb: conn = mydb.get_connection() cursor = conn.get_cursor() cursor.execute("update table1 set x = 1 where y = 2") cursor.close() cursor = conn.get_cursor() cursor.execute("update table2 set a = 1 where b = 2") cursor.close() I'd