Fix Python – Difference between `open` and `io.BytesIO` in binary streams

I’m learning about working with streams in Python and I noticed that the IO docs say the following:

The easiest way to create a binary stream is with open() with ‘b’ in the mode string:
f = open(“myfile.jpg”, “rb”)
In-memory binary streams are also available as BytesIO objects:
f = io.BytesIO(b”some initial binary data: \x00\x01″)

What is the di….

Fix Python – Can I redirect the stdout into some sort of string buffer?

I’m using python’s ftplib to write a small FTP client, but some of the functions in the package don’t return string output, but print to stdout. I want to redirect stdout to an object which I’ll be able to read the output from.
I know stdout can be redirected into any regular file with:
stdout = open(“file”, “a”)

But I prefer a method that doesn’….

Fix Python – Download large file in python with requests

Requests is a really nice library. I’d like to use it for downloading big files (>1GB).
The problem is it’s not possible to keep whole file in memory; I need to read it in chunks. And this is a problem with the following code:
import requests

def DownloadFile(url)
local_filename = url.split(‘/’)[-1]
r = requests.get(url)
f = open(loca….