#1:file文件open以后默认是r 只读模式 若是你要写入内容 报错:io.UnsupportedOperation: not writable
#2:r+ 可读可写 先写的话 从头开始覆盖写 读光标以后的内容 读写跟着光标走
#3:若是要写入中文 要注意编码格式
#4:w 只写 硬要去读 就会报错io.UnsupportedOperation: not readable
#5:w+ 可读可写 无论是w 仍是w+ 若是文件存在 就直接清空 再重写;若是文件不存在 则新建一个文件 而后写
# file=open("python12.txt","w",encoding='utf-8')
# file.write("8889999")
#6:a 追加 a+ 推荐
# file=open("python12.txt","a",encoding='utf-8')
# file.write("***柠檬班Python106666")
# #若是文件存在 就直接追加写 写在后面 若是不存在 则新建一个文件进行结果写入
# file=open("python13.txt","a",encoding='utf-8')
# file.write("\n***柠檬班Python106666")python
怎么移动光标?编码
file.seek(50) #控制光标移动 print(file.tell())#返回光标所在位置
能够指定读取的行数吗?code
file = open('xx') file.readlines()# 获取文件全部行列表内容 file.readlines()[n-1] #n是你须要读取的行数