python指定大小文件生成

使用特定大小的随机数生成,使用随机数生成器生成特定大小的字节,并将其写入文件中

import os


def generate_file(file_path, file_size_bytes):
    with open(file_path, 'wb') as file:
        file.write(os.urandom(file_size_bytes))


if __name__ == '__main__':
    # 生成一个大小为1MB的随机数据文件
    generate_file('caituotuo.docx', 1024 * 1024)
posted @ 2023-06-28 08:36  乐乐乐乐乐乐樂  阅读(31)  评论(0)    收藏  举报
jQuery火箭图标返回顶部代码