FileUtil.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:PyPPSPP 作者: justas- 项目源码 文件源码
def create_file(path, size):
    """Create a file with random contents and a given size"""

    print('Creating file: {} having a size of {} Bytes'.format(path, size))

    t_start = time.time()

    with open(path, mode='wb') as fp:

        # Write integer number of blocks
        data_left = size
        for _ in range(size // DATA_BLOCK):
            fp.write(os.urandom(DATA_BLOCK))
            data_left -= DATA_BLOCK

        # Write the remainder (if any)
        if data_left > 0:
            fp.write(os.urandom(data_left))

    print('File created in {} sec.'.format(time.time()-t_start))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号