>>> def show(opened):
... with opened as file:
... for line in file:
... print line.strip()
...
>>> show(open("test.txt"))
blah1
blah2
blah3
#
# Good! I wonder if I can do that with StringIO ...
#
>>> import StringIO
>>> show(StringIO.StringIO("
On Jan 27, 3:07 pm, Arnaud Delobelle wrote:
> On 27 Jan, 14:41, D HANNEY wrote:
> [...]
>
> See [1] for an explanation. Here is an idea: you could get round that
> by generating a class on the fly, if you don't mind changing the class
> of the object (untested):
&
On Jan 28, 1:31 pm, D HANNEY wrote:
>
> Your solution works if I change "type(obj)" to say "obj.__class__".
> If I don't make this change Python complains "TypeError: Error when
> calling the metaclass bases type 'instance' is not an acceptab