On Monday 20 October 2003 11:47 am, Moore, Paul wrote: > From: Alex Martelli [mailto:aleaxit at yahoo.com] > > > Basically, by exposing suitable methods an iterator could "make its > > abilities know" to functions that may or may not need to wrap it in > > order to achieve certain semantics -- so the functions can build > > only those wrappers which are truly indispensable for the purpose. > > Roughly the usual "protocol" approach -- functions use an object's > > ability IF that object exposes methods providing that ability, and > > otherwise fake it on their own. > > I'm glad you pointed this out. This whole thing was starting to sound > very like the sort of thing that the adaptation PEP was intended to > cover. Darn -- one more underground attempt to foist adaptation into Python foiled by premature discovery... must learn to phrase things less overtly, the people around here are too clever!!! > Can the people who need this get the capability via a suitable > adaptation approach? I'm not familiar enough with the technique to > be sure. If so, wouldn't that be a more general technique (as well > as being already available in 3rd party modules like PyProtocols). Yes, it would be more general and perfectly adequate for this task too, but would still require SOME level of cooperation from built-in types, such as the iterators returned by built-in iter. Adaptation is no black magic, just a systematic, clean, general way to use some capabilities if a type offers them and perhaps kludge them up with a wrapper if a type doesn't offer them but such a wrapper is possible. If an iterator built by iter(sequence) just won't let me know about what sequence it's iterating on and what its current index on it is, in SOME way or other, there's no way I can prise that information "by force" out of it -- I must treat it just like any other iterator that only exposes a .next() method and nothing more (because that's what it DOES expose). 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