Skip to content
Advertisement

ValueError : I/O operation on closed file

JavaScript

Here, p is a dictionary, w and c both are strings.

When I try to write to the file it reports the error:

JavaScript

Advertisement

Answer

Indent correctly; your for statement should be inside the with block:

JavaScript

Outside the with block, the file is closed.

JavaScript
Advertisement