【发布时间】:2014-04-01 18:08:52
【问题描述】:
我想分析 txt.file 的特定部分(第 48-392 行),但我在为 txt 文件的单行编号时遇到问题。 到目前为止,这是我能想到的:
with open ('kafka_hungerkuenstler.txt', encoding = 'utf-8') as f:
for line in f:
#I tried: enumerate (line)
#there should also be something like read_selected_lines (filename, 48,392) somewhere in
the code
print (line)
【问题讨论】:
-
是第49行(从0算起)还是第48行(从1算起)?
-
这是从 1 算起的第 48 行
-
用
for line in f.readlines()[47:392]:替换for line in f:
标签: python python-3.x enumerated-types