文件
文件扩展名
文件操作
# utf-8编码方式打开,Python3 字符串以unicode编码,unicode 隐式转换为 utf-8
# open函数内部 byte 类型转化为 str类型
f = open(filePath, mode='r', encoding='utf-8')
f = open(filePath, mode='r', encoding='GBK')mode
Last updated
# utf-8编码方式打开,Python3 字符串以unicode编码,unicode 隐式转换为 utf-8
# open函数内部 byte 类型转化为 str类型
f = open(filePath, mode='r', encoding='utf-8')
f = open(filePath, mode='r', encoding='GBK')Last updated
f = open('/path/to/SOMEFILE', mode, encode='utf8')
data = f.read(5) # 5个字符
f.close()for i in f.readlines():
print(i.strip())''.join([.strip(), 'iiii'])with open(/path/to/somefile, r) as f,open(/path/to/somefile, w) as f2 :
f.read()
f2.write()