Message378332
| Author |
iritkatriel |
| Recipients |
eric.smith, iritkatriel, miss-islington, ncoghlan, serhiy.storchaka, vstinner |
| Date |
2020年10月09日.15:02:32 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1602255752.62.0.889214959109.issue34067@roundup.psfhosted.org> |
| In-reply-to |
| Content |
For the original problem, how about this?
def process_file(file_or_path):
if isinstance(file_or_path, str):
# If string, open file
cm = open
else:
# Caller is responsible for closing file
cm = nullcontext
with cm(file_or_path) as file:
# Perform processing on the file |
|