[Python-ideas] str.find() and friends support a lists of inputs

Ryan Hiebert ryan at ryanhiebert.com
Thu Apr 17 22:28:36 CEST 2014


I like the idea. I agree with the assertion that has been discussed
previously that a string really shouldn't be iterable. Because of that, I
think that explicitly checking if it is str, and if not, using it as an
iterator, would be appropriate.


On Thu, Apr 17, 2014 at 3:14 PM, Andrew Barnert <
abarnert at yahoo.com.dmarc.invalid> wrote:

> On Apr 17, 2014, at 11:52, Alex Rodrigues <lemiant at hotmail.com> wrote:
>
> > It's a fairly common problem to want to .find() or .replace() or
> .split() any one of multiple characters.
>
> I like your solution, except for one thing. Explicitly requiring a list of
> arguments rather than, say, a tuple or an iterator, seems unnecessarily
> restrictive. However, allowing any iterable of strings doesn't work because
> a string is itself an iterable of strings.
>
> There are a few cases where Python deals with this problem by treating
> tuples specially (e.g., % formatting), but I don't think anyone wants to
> extend that solution.
>
> You could almost handle these problems with *args (replace replaces any of
> args[:-1] with args[-1]), except that all of them have optional parameters
> at the end.
>
> You could have a keyword-only argument to specify an iterable of strings
> (in which case you can't use any positional arguments), but that's a pretty
> weird interface.
>
> Or you could just add some new methods: split_any, replace_any, etc. But
> str already has a lot of methods; do we really want more?
>
> I'd love to see an answer that works here, because I agree that it would
> make a lot of code simpler, and especially code that novices want to write.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140417/b777434c/attachment.html>


More information about the Python-ideas mailing list