Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CondSeg Explicitly Close File #136

Open
Lauenburg opened this issue Nov 17, 2023 · 0 comments
Open

CondSeg Explicitly Close File #136

Lauenburg opened this issue Nov 17, 2023 · 0 comments

Comments

@Lauenburg
Copy link
Contributor

Describe the bug
In the following line, the file opened in the list comprehension is not explicitly closed. In Python, it's generally good practice to open files using the with statement, which ensures that the file is properly closed after its suite finishes, even if an exception is raised. Not closing files can lead to memory leaks or issues with file locks, especially in larger applications or if the code is run multiple times in a loop.

filelist = [line.rstrip('\n') for line in open(name)]

Expected behavior

The file is closed automatically. A better approach would be:

with open(name) as file:
    filelist = [line.rstrip('\n') for line in file]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant