读取文件,且不打印某一行。
f = open("myfile",'r',encoding="utf-8") for index,line in enumerate(f.readlines()): #此写法只适合读取小文件 if index==2: #第3行不打印 continue print(line.strip()) count = 0 for line in f: #高逼格写法 if count==2: count += 1 continue print(line.strip()) count += 1