#data=open(‘月亮代表我的心‘,encoding=‘utf-8‘).read()
#f=open(‘月亮代表我的心‘,encoding=‘utf-8‘)#内存对象=文件句柄
#data=f.read()
#print(data)
#f=open(‘月亮代表我的心2‘,‘r‘,encoding=‘utf-8‘)#read读文件
#f=open(‘月亮代表我的心2‘,‘w‘,encoding=‘utf-8‘)#write写文件会重新创建一个新文件
#f=open(‘月亮代表我的心2‘,‘a‘,encoding=‘utf-8‘)#append追加文字。只能单独使用
#f.write("材料部门提前组织有关机.\n")
#f.write("材料部门关机")
#print(f.readline())#打印第一行
f=open(‘月亮代表我的心‘,‘r‘,encoding=‘utf-8‘)
for index,line in enumerate(f.readlines()):#取文件的行的下标
if index==9:#到第九行
print(‘----23123423--- ------‘)
continue#跳出本次执行
print(line.strip())#打印并去掉空格和换行符
原文:https://www.cnblogs.com/buildydream/p/10010646.html