这是因为pycharm默认字符集是UTF-8,with open若不指定字符集,会保持原来的编码方式。在pycharm中查看该txt文件会乱码,用记事本打开不会
with open(file,'w') as f:
f.write(file)
解决办法:写入时指定字符集为UTF-8即可
with open(file,'w',encoding='utf-8') as f:
f.write(file)
这是因为pycharm默认字符集是UTF-8,with open若不指定字符集,会保持原来的编码方式。在pycharm中查看该txt文件会乱码,用记事本打开不会
with open(file,'w') as f:
f.write(file)
解决办法:写入时指定字符集为UTF-8即可
with open(file,'w',encoding='utf-8') as f:
f.write(file)