Adapt an iterator to behave like a file-like object in Python
<p>I have a generator producing a list of strings. Is there a utility/adapter in Python that could make it look like a file?</p>

<p>For example,</p>

<pre><code>&gt;&gt;&gt; def str_fn():
...     for c in 'a', 'b', 'c':
...         yield c * 3
... 
&gt;&gt;&gt; for s in str_fn():
...     print s
... 
aaa
bbb
ccc
&gt;&gt;&gt; stream = some_magic_adaptor(str_fn())
&gt;&gt;&gt; while True:
...    data = stream.read(4)
...    if not data:
...        break
...    print data
aaab
bbcc
c
</code></pre>

<p>Because data may be big and needs to be streamable (each fragment is a few kilobytes, the entire stream is tens of megabytes), I do not want to eagerly evaluate the whole generator before passing it to stream adaptor.</p>
