文件相关操作
f=open('test.txt',encoding='utf-8')
data=f.read()
print(data)
data=f.read()
print(data)
print(f.readable())
print('第1行',f.readline()) 读取第一行
print('第2行',f.readline()) 读取第二行
print('第3行',f.readline()) 。。。。。。。
...............
f.close()
f=open('test','w',encoding='utf8')
f.write('11111111\n')
f.write('222222222\n')
f.write('333\n4444\n555\n')
print(f.writable())
f.writelines(['555\n','6666\n'])
f.close()
f=open('test','a',encoding='utf-8')
f.write('写到文件最后')
f.close()
f=open('text','r+',encoding='utf8')
data=f.read()
print(data)
f.write('123')
f.close()
with open('xxx','r',encoding='gbk') as f:
data=f.read()
f.write(data)
f=open('test11.py','rb',encoding='utf-8')
f=open('test11.py','rb')
data=f.read()
print(data)
print(data.decode('utf-8'))
f.close()
f=open('test22.py','wb')
f.write(bytes('1111\n',encoding='utf-8'))
f.write('编程'.encode('utf-8'))
f=open('test22.py','ab')
f.write('编程'.encode('utf-8'))