# -*- 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格式?
with open(filename,'wb',encoding='utf-8') as f:
加一个 encoding 参数就行了