如何让代码查找文件大小以及如何让用户输入段大小
选择 | 换行 | 行号
- f = open("centaur_1.mpg","rb")
- #create a for loop and split file into 20 parts
- buffer=f.read() # readinto a large buffer to check its size
- #f.close() #close the file
- filesize=len(buffer)
- print filesize
- splitsize=int(filesize/segmentsize)
- f.seek(0) # reset to beginning of file
- #smallfbuf=[]
- for i in range(splitsize+1):
- filename="part"+str(i)+".mpg"
- f2= open(filename,"wb")
- buffer2 = f.read(splitsize)
- f2.write(buffer2)
- f2.close()
- f.close()
从上面的代码中,我如何获得文件大小和用户输入的SegmentSize