新学的文件操作,简单的一些整理

'''f = open('yesterday','r',encoding='utf-8')        # '读'
print(f.encoding )        #打印文件编码
print(f.name)             #打印文件名
print(f.seekable())       #判断能否指针移动
print(f.readable())       #判断文件是否能读
print(f.read())           #读取文件
print(f.flush())          #刷新,后面示列
print(f.close())          #关闭文件'''


''''f = open('yesterday','r',encoding='utf-8')
print(f.tell())          #查看指针位置  !单位是字符不是行
print(f.seek(10))        #指定指针位置
print(f.readline())      #从第一行的10字符后打印'''


#f = open('yesterday','w',encoding='utf-8')        #  'w'  写
#print(f.write())   #只写  会覆盖原目录!!!!

'''f = open('yesterday','a',encoding='utf-8')       #  'a'  追加
print(f.truncate(100))'''                             #   截断,不要再“写”下会清空文件

'''f = open('yesterday','r',encoding='utf-8')
print(f.readline())   #只读取第一行
print(f.readline())   #只读去第二行
....                  #......第n行'''


'''count = 0        #打印前十行,循环
f = open('yesterday','r',encoding='utf-8')
for i in f:
    if count == 9:
        print('----打印前十行----')
        count +=1
        continue
    print(i.strip())
    count +=1 '''

############################     一个个出现
'''import sys,time
for i in range(50):
    sys.stdout.write('#')
    sys.stdout.flush()
    time.sleep(0.1)'''
#f = open('yesterday','r+',encoding='utf-8')       #读写      写的会再文件最后 (常用)
#f = open('yesterday','w+',encoding='utf-8')       #写读       *
#f = open('yesterday','a+',encoding='utf-8')       #追加读     *

学习资料是老男孩视频,没钱等以后给老男孩补学费吧

原文地址:https://www.cnblogs.com/Smalllv/p/8695773.html