Skip to content

Commit 9aedf16

Browse files
committed
Free up file resources once text has been read
1 parent 77ee234 commit 9aedf16

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

micropython/examples/badger2040/qrgen.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
more about Badger 2040.
3333
""")
3434
text.flush()
35-
text.seek(0)
35+
text.close()
3636

3737
# Set the CODES list to contain the newQRcodeFilename (created above)
3838
CODES = [newQRcodeFilename]
@@ -84,9 +84,16 @@ def draw_qr_code(ox, oy, size, code):
8484
def draw_qr_file(n):
8585
display.led(128)
8686
file = CODES[n]
87-
codetext = open("qrcodes/{}".format(file), "r")
8887

89-
lines = codetext.read().strip().split("\n")
88+
try:
89+
codetext = open("qrcodes/{}".format(file), "r")
90+
91+
lines = codetext.read().strip().split("\n")
92+
93+
codetext.close()
94+
except:
95+
lines = ["", "", "", "", "", "", "", "", "", ""]
96+
9097
code_text = lines.pop(0)
9198
title_text = lines.pop(0)
9299
detail_text = lines

0 commit comments

Comments
 (0)