2016-09-18 100 views

回答

1

文件是字節序列,Python可以讓你寫字節。只需寫\x00個字符來產生只包含0位的字節。

打開文件的二進制和你只需要編寫許多這樣的字節:

with open(filename, 'wb') as binfile: 
    binfile.write(b'\x00' * desired_length)