Skip to content

Commit 4e63db0

Browse files
committed
Update excel_to_base64 to always close file handles
1 parent 401f4cf commit 4e63db0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/penn_chime/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def dataframe_to_base64(df: pd.DataFrame) -> str:
9-
"""Converts a dataframe to a base64-encoded CSV representation of that data.
9+
"""Converts a dataframe into csv base64-encoded data.
1010
1111
This is useful for building datauris for use to download the data in the browser.
1212
@@ -18,7 +18,7 @@ def dataframe_to_base64(df: pd.DataFrame) -> str:
1818
return b64
1919

2020

21-
def excel_to_base64(str_excel_filename) -> str:
22-
data = open(str_excel_filename, 'rb').read()
23-
b64 = b64encode(data).decode()
24-
return b64
21+
def excel_to_base64(filename: str) -> str:
22+
"""Converts an excel document into base64-encoded data."""
23+
with open(filename, 'rb') as fin:
24+
return b64encode(fin.read()).decode()

0 commit comments

Comments
 (0)