【发布时间】:2015-07-09 08:06:56
【问题描述】:
我有一个名为files.txt 的文件,其中包含文件名。像这样:
L150216_1.txt_out
L150216_2.txt_out
L150216_3.txt_out
我正在像这样打开files.txt:
with open("files.txt") as f:
file_List = f.read()
pass #Do some calculations with the file_List
然而,事实证明,file_List 看起来不像文件名列表,而是字符列表。 IE。而不是 L150216_1.txt_out 它将是 L、1、5、0 等等。
如何使用"with" 命令打开文件以读取行而不是字符?
【问题讨论】:
标签: python list with-statement