生成指定大小的文件

 1 #!/usr/bin/env python
 2 # -*- coding: utf-8 -*-
 3 
 4 import os
 5 import random
 6 
 7 def genSizeFile(fileName, fileSize):
 8     #file path
 9     filePath="Data"+fileName+".txt"
10 
11     # 生成固定大小的文件
12     # date size
13     ds=0
14     with open(filePath, "w") as f:
15         while ds<fileSize:
16             f.write(str(round(random.uniform(-1000, 1000),2)))
17             f.write("\n")
18             ds=os.path.getsize(filePath)
19     # print(os.path.getsize(filePath))
20 
21 # start here.
22 genSizeFile("20480k",20*1024*1024)

 

posted @ 2017-01-09 10:30  逍遥无名  阅读(989)  评论(0编辑  收藏  举报