侠之大者为国为民 2019-05-23 11:12 采纳率: 0%
浏览 270

使用seek方式创建的文件,为什么默认打开编码是ANSI?

# -*- coding: utf-8 -*-
import math

DW={'K':1,'M':2,'G':3,'T':4,'P':5}

SPACE=int(math.pow(1024,DW['M']))

def createBigFile(n):
    filename='big.txt'
    with open(filename,'wb') as f:
        f.seek(SPACE*n-1)
        #f.truncate()
        f.write(b'\x00')

if __name__=='__main__':
    createBigFile(1)

使用上述代码生成的文件,notepad打开默认格式为ANSI,怎么样默认为UTF-8格式?

  • 写回答

1条回答 默认 最新

  • Steven·简谈 2019-05-23 13:50
    关注
    with open(filename,'wb',encoding='utf-8') as f:
    

    加一个 encoding 参数就行了

    评论

报告相同问题?