from itertools import islice
filename="D:/20221028.txt"
new_dir="D:/elements2.txt"
new = open(new_dir, "w+")
count1=23 #起始行
count2=24 #终止行
while count1 < 1200000:
count1=count1+23
count2=count2+23
f = open(filename, "r")
for a in islice(f, count1, count2):
new.write(a)
f.close()
new.close()
没有while的时候可以取一行,但加了while后,运行没有报错,但,没有数据了。
缩进乱了,用代码块贴一下代码
```python
from itertools import islice
filename="D:/20221028.txt"
new_dir="D:/elements2.txt"
new = open(new_dir, "w+")
count1=23 #起始行
count2=24 #终止行
while count1 < 1200000:
count1=count1+23
count2=count2+23
f = open(filename, "r")
for a in islice(f, count1, count2):
new.write(a)
f.close()
new.close()