【发布时间】:2021-08-20 20:26:00
【问题描述】:
我有 test.txt 文件:
"hi there 1, 3, 4, 5"
当我使用 python 读取它时,如何逐部分读取它,例如首先我读取前 4 个字符,然后读取接下来的 4 个字符,然后读取所有左侧。
我的代码在这里:
with open(file, 'r', encoding='utf-8', errors='ignore') as f:
lines = f.read(4)
使用此代码我只能读取前 4 个字符,知道我可以在循环中准备好每 4 个字符直到读取所有字符吗?
【问题讨论】:
-
你到底想做什么?
标签: python python-3.x file