This article describes a simple way to split a file in Python. Share to everyone for your reference. Specific as follows:
Some sites have a limit on file size when uploading files, so you can split large files into smaller files and upload them.
#!/usr/bin/env pythondef split (filename, size): fp = open (filename, ' RB ') i = 0 n = 0 temp = open (filename + '. Part ' +str (i), ' WB ') buf = Fp.read (1024x768) while (True): temp.write (buf) buf = Fp.read (1024x768) if ( BUF = = "): print filename+ '. Part ' +str (i) + '; ' Temp.close () fp.close () return n + = 1 if (n = = size): n = 0 print filename+ '. Part ' +str (i )+';' i + = 1 temp.close () temp = open (filename+ '. Part ' +str (i), ' WB ') if __name__ = = ' __main__ ': name = Raw_input (' Input filename: ') Split (name, 307200) #分割后每个文件300M
Hopefully this article will help you with Python programming.