我有一个 list ,我通读过:
doc= open('text.txt')
d=doc.readlines()
但我需要转到第 10000 个字符并从那里读取接下来的 300 个字符。首先,您知道如何按字符读取列表吗?谢谢!!
请您参考如下方法:
doc= open('text.txt')
d=doc.readlines()
这将为您提供线路列表。您需要改用 read。
我愿意
with open('text.txt') as doc:
doc.read(10000) # ignore result
result = doc.read(300) # read 300 chars from there.
请注意,如果您使用 doc.seek(100000) 而不是“随风”读取 10000 字节,它可能会更快,但在那种情况下,您必须考虑 MS 的 CRLF 转换-DOS 文本文件,因此您可以有不同的偏移量。
