三元运算:
a=1 b=2 max=a if a > b else b print(max)
open(file,"r",encoding="utf-8")#encoding:告诉python文件以哪种编码编写
open(file,"rb")#以二进制模式打开文件,主要用于图、视频,进行网络传输的文本
chardet#智能检测编码
f = open(‘C:/Users/Administrator/Desktop/100.txt‘, ‘rb‘) data = f.read() # print(data) f.close() import chardet print(chardet.detect(data)) print(data.decode(‘ascii‘)) {‘encoding‘: ‘ascii‘, ‘confidence‘: 1.0, ‘language‘: ‘‘} 需要先安装 pip install chardet