What is the difference between "open (...)" and "close (open (...))"

From my point of view,

with open(...) as x: 

should close the file after the with statement completes. However now i see

 with closing(open(...)) as x: 

in one place, looked around and realized that closing should close the file after completing the with statement.

So what is the difference between closing a file and closing file?

+5
source share
1 answer

Assuming contextlib.closing and standard, inline open , closing excess here. This is a wrapper that allows you to use with statements with objects that have a close method but do not support the use of context managers. Because the file objects returned by open are context managers, closing not required.

+15
source

All Articles