How to chunk any type of file in python and convert that file into string -


how chunk file of type pieces , converted string of python?

i need create web app runs on php backend , when upload file in it... safety needs split n pieces of equal sizes , convert strings easy transfer other storage drive

edit: updated question, might easiest use library suited problem - requests comes mind here

here's chunkify splitting list of n parts of approximately equal length

def chunks(l, n):     """ yield successive n-sized chunks l.     """     in range(0, len(l), n): # use xrange if you're using python 2 - won't create range list.         yield l[i:i+n] 

and convert string use:

":".join(",".join(str(elem) elem in chunk) chunk in chunks(l, n)) 

for l = [1, 2, 3, 4, 5, 6] prints:

>>> "1,2,3:4,5,6" 

Comments