我的文件未正确关闭,我无法找出原因:
open_sample_file = codecs.open(ssis_txt_files_2[a], 'r', "utf-16")
whatever = open_sample_file.readlines()
open_sample_file.close
print(open_sample_file)
输出:
<codecs.StreamReaderWriter object at 0x0331F3B0>
输出不应该返回None
吗?你知道吗
Tags:
你得打电话
open_sample_file.close()
首先,需要调用close方法:
然后,结果是一个关闭的文件,而不是
None
。你知道吗最后,在Python中处理文件的常用方法是使用with-statements,它负责为您关闭文件:
相关问题 更多 >
编程相关推荐