Skip to content

Commit f17b736

Browse files
author
Arjan Egges
committed
Minor fix in SQLite context manager
1 parent 1fab596 commit f17b736

File tree

1 file changed

+3
-2
lines changed
  • 7 - dealing with errors/monadic-error-handling

1 file changed

+3
-2
lines changed

7 - dealing with errors/monadic-error-handling/example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
class SQLite():
77
def __init__(self, file='application.db'):
8-
self.file=file
8+
self.file = file
9+
self.conn = None
910
def __enter__(self):
1011
self.conn = sqlite3.connect(self.file)
1112
return self.conn.cursor()
1213
def __exit__(self, type, value, traceback):
13-
self.conn.close()
14+
if self.conn: self.conn.close()
1415

1516
class NotFoundError(Exception):
1617
pass

0 commit comments

Comments
 (0)