'''
知识点汇总
1-文件
    1- Python2  File  --  Python3   TextIOWrapper
2-文件的打开:
    1- open(file,mode)-----函数---有返回值--文件对象
    2- 一定要有file文件路径(路径、文件名、文件格式)  否则
        TypeError: Required argument 'file' (pos 1) not found
    3- fo = open(fileDir)---只读
    4- 路径的写法
        1- fileDir = 'G:/pyTest1.txt'
        2- fileDir2 = 'G:\\pyTest1.txt'
        3- fileDir3 = r'G:\pyTest1.txt'--取消转义
    5- 路径
        1- 绝对路径--根目录开始的   G:/pyTest1.txt
        2- 相对路径 ./当前位置     ../ 上一级
    6- 读模式
        0- 如果该文件不存在会报错!
        1- fo = open(fileDir,'r') ===  fo = open(fileDir) 
        2- fo.tell()---从0开始
        3- fo.read(2)----读2个字符
        4- fo.read()--读全部内容
        5- 文件中的换行是2个长度  \n   ‘a\nb’---字符串中是一个
        6- fo.close()--关闭文件

        7- 移动文件指针位置: seek()
            1- 0模式---绝对位置模式   fo.seek(1,0)
            前提:python3 一定在'rb'模式下---二进制模式--非文本文件(图片)
                2- 1模式---当前位置开始移动 fo.seek(移动的位数,模式1)
                    移动的位数 正数:向后移   负数:向前移

                3- 2模式---从尾部
                    1- fo.seek(-1,2) 
                    2- 移动的位数 正数:向后移   负数:向前移
            案例:
            fileDir = 'G:/pyTest1.txt'
            fo = open(fileDir,'rb')
            print('读前',fo.tell())
            print(fo.read(2))
            print('读后',fo.tell())
            fo.seek(2,2)
            print('移动后',fo.tell())

        8- readline读取一行
            1- 该方法返回是 print(type(fo.readline()))--  <class 'str'>
            2- 文件指针会做相应的偏移

        9- readlines读取所有行
            1- 该方法返回是 print(type(fo.readlines()))--  <class 'list'>
            区别:
                1- fo.read()----返回str
                2- fo.readlines()---返回是list---每一行是里面一个元素!
            2- fo.read().splitlines()---返回list  而且去掉换行符
    7- 文件写模式:
        1- fo = open(fileDir,'w')
        2- 如果该路径下的文件存在---会清空!
        3- 如果该路径下的文件不存在---会新建!
        4- 在pycharm里面,你执行了fo.write('123')--可以直接写进去
        5- fo.write('123')--返回值---写的字符长度
        6- fo.flush() 强行写入文件
        7- fo.close() 关闭文件会强行写入文件
    8- 追加模式 a
        1- 只是为了在文件末尾追加内容而打开文件
    9- With open 方式
        1- with open(fileDir) as rFile:----rF = open(fileDir)
        2- 可以省略fo.close()
        3- 操作多个文件

'''''

'''
seek:
    1- (1,模式)---0模式----绝对位置,从0开始---配套  ‘r’
        处理:文本文件---txt、log ----返回--str

    2- (1,模式)---1模式----当前位置,开始
        文件打开的模式一定是  rb---  读二进制(bin)---.pcap格式、图片、音频、视频文件用rb模式打开
    3- (1,模式)---2模式----尾部位置,开始---rb---  读二进制(bin)

windows --文件里面的换行--\r\n    2个长度     '\n'---一个    linux-一个
'''
# fileDir = 'G:/pyTest1.txt'
fileDir2 = 'G:\\pyTest1.txt'
# fileDir3 = r'G:\pyTest1.txt'#取消转义
#1- 读模式
# fo = open(fileDir2,'r')#r 缺省的---可以不写      读模式:文件不存在---会报错
# print(fo.tell())#当前文件指针位置---开始在 0
# print(fo.read())#返回是--str    空着不写--全部--返回是str
# print(fo.tell())#
# fo.close()#关闭文件---后续不能操作该文件呢
#
# print(fo.read(2))#返回是--str    空着不写--全部--返回是str
# fo.seek(-1,1)#  r   读模式    0 模式---从开始算起
# print('移动后的文件指针位置:',fo.tell())#
# fo.close()#关闭文件---后续不能操作该文件呢

# print(fo.readline())#1- 读一行内容   返回是str
# print(fo.readlines())#2- 读所有行   返回是列表  每一行是列表一个元素
# print(fo.read().splitlines())#读取所有行--去换行符

#2- 写
#文件不存在--不会报错--新建文件    文件存在--会清空
# fo = open(fileDir2,'w')# w写模式  写模式不能读
# fo.write('123456')#实际原理没有写进去-
# fo.flush()#刷新---写入磁盘
# fo.close()#关闭---也有保存的功能

# dataList = ['a','b','c','d']
# fo = open(fileDir2,'w')
# for one in range(0,4):
#
#     fo.write(dataList[one])

with open(fileDir2,'r') as readF,open('','w') as wFile:#1- 可以省略fo.close()  2、操作多个文件
    #文件操作代码
    print()