[Python-Dev] Iterable String Redux (aka String ABC)
Antoine Pitrou
solipsis at pitrou.net
Tue May 27 23:59:25 CEST 2008
Georg Brandl <g.brandl <at> gmx.net> writes:
> You wrote:
>
> > If we stay minimalistic we could consider that the three basic
operations that
> > define a string are:
> > - testing for substring containment
> > - splitting on a substring into a list of substrings
> > - slicing in order to extract a substring
>
> I argued that instead of split, find belongs into that list.
> (BTW, length inquiry would be a fourth.)
Well, find() does test for substring containment, so in essence it is in that
list, although in my first post I chose '__contains__' as the canonical
representative of substring containment :-)
And, you are right, length inquiry belongs into it too.
> That the other methods, among them split, can be implemented in terms
> of those, follows from both sets of basic operations.
When I wrote "the three basic operations that define a string", perhaps I
should have written "the three essential operations" instead. I was not
attempting to give implementation guidelines but to propose a semantic
definition of what constitutes a string and distinguishes it from other kinds
of objects.
Anyway, I think we are picking on words here.
Do we agree on the following basic String interface :
['__len__', '__contains__', '__getitem__', 'find', 'index', 'split', 'rsplit']?
cheers
Antoine.
More information about the Python-Dev
mailing list