import os # 当前操作目录,os.chdir() 切换操作目录
>>> import os
>>> os.getcwd()
'C:\\ProgramFiles\\Python36'
open(“路径”,“模式“,encoding= “编码”)
(1.)路径
1. ”c:\\path\\data.txt”
2. r”c:\path\data.txt”
3. “data.txt”
(2) 模式
1. 文本
“r” # 只读
“w” # 写
“rw” # 读写
“r+” # 读写
“w+” # 先创建新文件,再读
“a” # 增加
2. 二进制
“*b” # 二进制的读取
通用操作
读取
num = (open("names.txt","r",encoding= "utf-8").read())#打开文件,并读取
# "r""w"文件的读取不能同时操作
num = (open("names.txt","w",encoding= "utf-8"))