Python USES cStringIO to implement the method of temporary memory file access

  • 2020-04-02 14:46:11
  • OfStack

This article illustrates how python USES cStringIO for temporary memory file access. Share with you for your reference. Specific analysis is as follows:

If you want to read a file from the network for processing, but you don't want to save the file to the hard disk, you can use the cStringIO module for processing


res = urllib2.urlopen(pic,timeout=10)
f = cStringIO.StringIO(res.read())

F is a file object,
It and: f = open('c:/1.jpg','rw')   Open the same file
An in-memory file can be read and written as if it were a local file

I hope this article has helped you with your Python programming.


Related articles: