Q:

Python str to file type

I'm downloading an image with the requests library and then writing the image to disk, then reopening the new file to pass on into another function.
if __name__ == '__main__':
r = requests.get(IMAGE_STREAM, stream=True)
output = StringIO.StringIO()
with open('1.jpg', 'wb') as f:
    f.write(r.content)

f = open('1.jpg')
img = Image.open(f)

Is there a method where I can skip the writing and reopening stage and pass the file straight into my end function?

A:

Well, you have the StringIO object:
output = StringIO.StringIO(r.content)

Then just pass output to Image.open.

