why not "'in' in 'in'"?

Bjorn Pettersen BPettersen at NAREX.com
Thu Jun 13 15:27:46 EDT 2002


> From: holger krekel [mailto:pyth at devel.trillke.net] 
> 
> Bjorn Pettersen wrote:
> > > From: Grant Griffin [mailto:not.this at seebelow.org]
> > > That's not a bad suggestion, Mark, but if I did that I guess 
> > > I would be forever wondering if I was testing whether the 
> > > first one was in the second or the second one was in the 
> > > first.  Again, it doesn't read nearly as well as:
> > > 
> > >    if x in subject:
> > >        ...
> > > 
> > > which leaves no doubt.
> > 
> > Ok, how about:
> > 
> > >>> class mystr(str):
> > ...   def __contains__(self, s):
> > ...     return self.find(s) >= 0
> > ...
> > >>> 'hello' in mystr('hello world')
> > 1
> > >>> 'foo' in mystr('hello world')
> > 0
> > >>>
> 
> that's fine. but usually you don't want to make up an 
> instance for every string you get from somewhere. 
> I still think that patching 'stringobject.c' to get the 
> reasonable behaviour might be worth a try for python2.3. 
> 
>     holger

I'm in total agreement, but the issue has been discussed here before on
numerous occations... nothing ever came of any of it.

-- bjorn





More information about the Python-list mailing list