On Fri, 30 Apr 2021 at 17:08, David Álvarez Lombardi <alvarezd...@gmail.com>
wrote:

> I propose a syntax for constructing/filtering strings analogous to the one
> available for all other builtin iterables. It could look something like
> this.
>
> >>> dirty = "f8sjGe7"
> >>> clean = c"char for char in dirty if char in string.ascii_letters"
> >>> clean
> 'fsjGe'
>
> Currently, the best way to do this (in the general case) seems to be the
> following.
> >>> clean = "".join(char for char in dirty if char in string.ascii_letters)
>
> But I think the proposed syntax would be superior for two main reasons.
>

I’m not against a specialised string generator construct per-se (I’m not
for it either :) as it’s not a problem I have experienced, and I’ve been
doing a lot of string parsing/formatting at scale recently) but that
doesn’t mean your use-cases are invalid.

To me, the chosen syntax is problematic.  The idea of introducing
structural logic by using “” seems likely to cause confusion. Across all
languages I use, quotes are generally and almost always used to introduce
constant values.  Sometimes, maybe, there are macro related things that may
use quoting, but as a developer, if I see quotes, I’m thinking: the runtime
will treat this as a constant.

Having a special case where the quotes are a glorified function call just
feels very wrong to me.  And likely to be confusing.

Steve




>    - Consistency with the comprehension style for all other iterables
>    (which seems to be one of the most beloved features of python)
>    - Confusion surrounding the str.join(iter) syntax is very well
>    documented
>    
> <https://stackoverflow.com/questions/493819/why-is-it-string-joinlist-instead-of-list-joinstring>
>    and I believe it is particularly unintuitive when the string is empty
>
> I also believe the following reasons carry some weight.
>
>    - Skips unnecessary type switching from str to iter and back to str
>    - Much much MUCH more readable/intuitive
>
> Please let me know what you all think. It was mentioned (by @rhettinger)
> in the PBT issue <https://bugs.python.org/issue43900> that this will
> likely require a PEP which I would happily write if there is a positive
> response.
>
> --
>
> *David Álvarez Lombardi*
> Machine Learning Spanish Linguist
> Amazon | Natural Language Understanding
>   Boston, Massachusetts
>   alvarezdqal <https://www.linkedin.com/in/alvarezdqal/>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/MVQGP4GGTIWQRJTSY5S6SDYES6JVOOGK/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KKE25ZZP62CLTWQWKLZCNL7NKTRIRSL6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to