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)