更新时间:2023-02-05 09:29:01
您应该使用枚举器和迭代器,而不是将整个文件读取到内存中.
You should use enumerators and iterators rather than reading the entire file to memory:
with open('something.txt', 'r') as f:
for i, line in enumerate(f, start=1):
print('{} = {}'.format(i, line.strip()))