I/O operation on closed file.

with open(r'G:/1h.csv', 'w+', newline='') as c:
	writer_csv = csv.writer(c,dialect="excel"
with open(r"G:/1h.txt", 'r', encoding='utf8')as f:
	print(f.readlines())

报错:I/O operation on closed file.

ValueError IO operation on closed file表示处理了已经被关闭的数据,在python 中 with语句的上下文会帮助处理,也就是说,当python的处理代码不对齐的时候会出现这种情况。

修改为:

with open(r'G:/1h.csv', 'w+', newline='') as c:
	writer_csv = csv.writer(c,dialect="excel"
	with open(r"G:/1h.txt", 'r', encoding='utf8')as f:
		print(f.readlines())

即可

参考: link.

你可能感兴趣的:(I/O operation on closed file.)