Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 39
    The disadvantage of this solution is, that the entire file is loaded into ram before saved to disk, just something to keep in mind if using this for large files on a small system like a router with limited ram.
    – tripplet
    Commented Nov 18, 2012 at 13:33
  • 2
    @tripplet so how would we fix that? Commented Jul 30, 2015 at 15:10
  • 11
    To avoid reading the whole file into memory, try passing an argument to file.read that is the number of bytes to read. See: gist.github.com/hughdbrown/c145b8385a2afa6570e2
    – hughdbrown
    Commented Oct 7, 2015 at 16:02
  • @hughdbrown I found your script useful, but have one question: can I use the file for post-processing? suppose I download a jpg file that I want to process with OpenCV, can I use the 'data' variable to keep working? or do I have to read it again from the downloaded file? Commented Nov 16, 2016 at 12:29
  • 7
    Use shutil.copyfileobj(mp3file, output) instead.
    – Mmmh mmh
    Commented Nov 6, 2017 at 14:20