On 2005 Jan 13, at 22:43, Paramjit Oberoi wrote: > On Thu, 13 Jan 2005 20:40:56 +0100, Alex Martelli <aleax at aleax.it> > wrote: >> >> So please explain what's imperfect in wrapping a str into a StringIO? > > If I understand Philip's argument correctly, the problem is this: > > def print_next_line(f: file): > print f.readline() > > s = "line 1\n" "line 2" > > print_next_line(s) > print_next_line(s) > > This will print "line 1" twice. Ah! A very clear example, thanks. Essentially equivalent to saying that adapting a list to an iterator ``rewinds'' each time the ``adaptation'' is performed, if one mistakenly thinks of iter(L) as providing an _adapter_: def print_next_item(it: iterator): print it.next() L = ['item 1', 'item 2'] print_next_item(L) print_next_item(L) Funny that the problem was obvious to me for the list->iterator issue and yet I was so oblivious to it for the str->readablefile one. OK, this does show that (at least some) classical cases of Adapter Design Pattern are unsuitable for implicit adaptation (in a language with mutation -- much like, say, a square IS-A rectangle if a language does not allow mutation, but isn't if the language DOES allow it). Thanks! Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4