By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

How to let code find the file size and how to let user input segment size

P: 1
Expand|Select|Wrap|Line Numbers
  1. f = open("centaur_1.mpg","rb")
  2. #create a for loop and split file into 20 parts
  3. buffer=f.read()  # readinto a large buffer to check its size
  4. #f.close() #close the file
  5. filesize=len(buffer)
  6. print filesize
  7. splitsize=int(filesize/segmentsize)
  8. f.seek(0)  # reset to beginning of file
  9. #smallfbuf=[]
  10. for i in range(splitsize+1):
  11.     filename="part"+str(i)+".mpg"
  12.     f2= open(filename,"wb")
  13.     buffer2 = f.read(splitsize)
  14.     f2.write(buffer2)
  15.     f2.close()
  16. f.close()

from the above codes, how do i get the filesize and the user to input segmentsize
Jul 3 '14 #1
Share this Question
Share on Google+
1 Reply


sicarie
Expert Mod 2.5K+
P: 4,677
It looks like you can import os and then use the getsize() function to see the filesize:

Expand|Select|Wrap|Line Numbers
  1. import os
  2. size = os.path.getsize('centaur_1.mpg')
  3. print size
  4.  
So I got that from Googling "python get file size" and I would Google "python get user input" to allow the user to input the segment size.

Good luck!
Jul 23 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.