如何在一行中读取A列到B列的所有字符

Ope*_*way 1 python text-processing

是否有可能在Python中,给定10000行的文件,其中所有这些都具有以下结构:

1,2,xvfrt ert5a fsfs4 df f fdfd56,234

或类似的,读取整个字符串,然后在另一个字符串中存储从第7列到第17列的所有字符,包括空格,所以新字符串将是

"xvfrt ert5a"?

非常感谢

Sil*_*ost 7

lst = [line[6:17] for line in open(fname)]
Run Code Online (Sandbox Code Playgroud)


Nad*_*mli 5

another_list = []
for line in f:
    another_list.append(line[6:17])
Run Code Online (Sandbox Code Playgroud)

或者作为生成器(内存友好的解决方案):

another_list = (line[6:17] for line in f)
Run Code Online (Sandbox Code Playgroud)