What exactly is StringIO used for?
I have been looking around the internet for some examples. However, almost all of the examples are very abstract. And they just show "how" to use it. But none of them show "why" and "in which circumstances" one should/will use it?
p.s. not to be confused with this question on stackoverflow: StringIO Usage which compares string and StringIo.
It’s used when you have some API that only takes files, but you need to use a string. For example, to compress a string using the gzip module in Python 2: