import shutil
import os
###第一步写文件
'''
with open('test.txt', 'w',encoding='utf-8') as f:
f.write("1111111111\n")
f.write("2222222222\n")
f.write("3333333333\n")
f.write("aaaaaaa\r\n")
f.write("bbbbbbb\r\n")
f.write("ccccccc\r\n")
'''
###第二步 过滤文件空行,再重新写入新的文件
file_data=''
i=0
with open('test.txt', 'r', encoding='utf-8') as f:
for line in f.readlines():
print(str(i) + " line=" + line + str(line != '') + str(len(line))) ## debug
line = line.strip()
if(len(line) > 1): ## 判断条件,过滤空行
file_data += line
file_data += '\r\n'
i = i + 1
#print(str(i) + " line="+line) #打印查看每一行的内容
with open('test5.txt', "w", encoding="utf-8") as f:
f.write(file_data)
print('文件创建成功!')
'''
思路:在某一行打上"#"标记,根据行号来标记
i = 0
if i > 31 and i < 34:
line = '#' + line
print(line)
file_data += line + '\r\n'
i += 1
'''