Skip to content

SIM115: with context handler for opening files #17

@MartinThoma

Description

@MartinThoma

Explanation

Using a context handler is shorter and avoids the error of forgetting to close a file handle.

Example

# Bad
f = open(...) 
... # (do something with f)
f.close() 

# Good
with open(..) as f:
   ... # (do something with f)

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions