with open("yesterday","r") as f,\
open("yesterday2","r") as f2: 同时打开两个文件
for line in f :
print(line)
当with代码块执行完毕时,内部会自动关闭并释放文件资源。
字符编码:
Unicode 包含GBK和UTF-8
Unicode encode 编码码成UTF-8 encode编码码成GBK
UTF-8 和GBK decode 编码成 Unicode
s="你好"
print(s.encode("gbk")) 把s编码成GBK
s_to_gbk = s.decode("utf-8").encode("gbk")
print(s.encode("utf-8").decode("utf-8").encode("gb2312").decode("gb2312"))
编码成utf-8,解码成Unicode 再编码成gb2312 再解码gb2312成Unicode
时间: 2024-12-28 15:24:16