一、字符编码格式

二、文件读取原理
 读写操作  举例:准备一个a.txt  然后创建文件对象读取 readlines可以读取文件全部内容,并建立列表,读取中文时需要加上encoding=‘UTF-8’
file=open('a.txt','r',encoding='UTF-8')
print(file.readlines())
file.close()
结果: 
三、常见的文件打开模式
 举例:图片的复制操作: 
四、文件对象的常用方法

五、with语句
 举例1:
with open('a.txt','r',encoding='UTF-8') as file:
print(file.read())
举例2:
class Mycontent(object):
def __enter__(self):
print("enter方法被调用了。。。")
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print('exit方法被调用了。。。')
def show(self):
print("show方法被调用了。。。")
with Mycontent() as file:
file.show()
结果如下:  举例3:图片复制 
六、os模块的常用方法
1、目录操作  举例1:
import os
os.system('calc.exe')
os.system('notepad.exe')
os.startfile('C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe')
2、os模块操作目录相关函数  3、os.path模块操作目录相关函数  举例:
七、课堂案例
1、列出指定文件下的py文件  2、遍历文件下的所有文件包括子目录下的文件 下面是遍历文件下的所有文件包括目录:  结果:  将路径拼接起来:  结果: 
|