2016-09-18 99 views

回答

1

文件是字节序列,Python可以让你写字节。只需写\x00个字符来产生只包含0位的字节。

打开文件的二进制和你只需要编写许多这样的字节:

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