基本操作
# 打开文件file = open("README")# 读取文件text = file.read()print(text)# 关闭文件file.close()
# 打开文件src_file = open("README")des_file = open("README[副本]", "w")# 复制文件while True:text = src_file.readline()if not text:breakdes_file.write(text)# 关闭文件src_file.close()des_file.close()
文件编码
第一行,声明文件编码
# *_* coding:UTF-8 *_*hello_str = "hello,你好"print(hello_str)
