DEV Community

Discussion on: How would you rewrite this Python code?

Collapse
 
tadaboody profile image
Tomer

Actually the context manager solves this by only opening/closing the fp if it isn't to stdout so it might be the best solution

Collapse
 
rhymes profile image
rhymes

Oh yes, you're right :-)

+1 to the context manager, though it might be overkill if the function is used only once.