在字符串写入文件时,有时会因编码问题导致无法写入,可在open方法中指定encoding参数 fp= open(filename, 'w', encoding='utf-8') 转自:https://www.cnblogs.com/stuqx/p/7291973.html