标签:enum 计数 open font python encoding enc sys int
#!\usr\bin\env\python
# _*_ coding:utf-8 -*9
#文件打开
‘‘‘data = open("yest",encoding="utf-8").read()
f = open("yest2","a",encoding="utf-8")
f.write("afoafjajf")
data = f.read()
print(‘----read‘,data)
f.close() ‘‘‘
#文件操作功能
f = open("yest2",‘r+‘,encoding="utf-8") #读写
#f =open("yest2",‘w+‘,encoding="utf-8") #写读
#f =open("yest2",‘a+‘,encoding="utf-8") #追加读写
#f =open("yest2",‘rb‘,encoding="utf-8") #二进制文件
print(f.readline())
print(f.readline())
print(f.readline())
print(f.tell()) #tell方法是返回文件当前位置
f.write("-------diao-----------")
print(f,readline())
#进度条实例
import sys,time
for i in range(20):
sys.stdout.write("#")
sys.stdout.flush()
time.sleep(0.1)
#实现从 第一行打印至第九行,最优循环方法,采用计数函数count
count=0
for line in f:
if count==9:
print("我是分割线")
count+=1
continue
print(line)
#还可以采用取下标的方法实现
for index,line in enumerate(f.readline()):
if index==9:
print("我是分割线")
continue
print(line.strip())
#直接打印前5行
for i in range(5):
print(f.readline())
标签:enum 计数 open font python encoding enc sys int
原文地址:https://www.cnblogs.com/lindong0602/p/9237862.html