On Sat, May 1, 2021 at 6:23 AM Rob Cliffe via Python-ideas
<python-ideas@python.org> wrote:
> Yes I agree your examples read nicely, without the usual boilerplate.  
> Whether this is worth adding to the language is a moot point.  Every addition 
> increases the size of the compiler/interpreter, increases the maintenance 
> burden, and adds to the learning curve for newbies (and not-so-newbies).  As 
> far as I can see in every case
>     c'SOMETHING'
> can be replaced by
>     ''.join(SOMETHING)
> or
>     str.join('', (SOMETHING))
> Having many ways to do the same thing is not a plus.
>

(We can ignore the str.join('', THING) option, as that's just a
consequence of the way that instance method lookups work, and
shouldn't happen in people's code (although I'm sure it does).)

If people want a more intuitive way to join things, how about this?

>>> class Str(str):
...     __rmul__ = str.join
...
>>> ["a", "b", "c"] * Str(",")
'a,b,c'

Or perhaps:

...     def __rmul__(self, iter):
...             return self.join(str(x) for x in iter)
...
>>> ["a", 123, "b"] * Str(" // ")
'a // 123 // b'

If you want an intuitive way to join strings, surely multiplying a
collection by a string makes better sense than wrapping it up in a
literal-like thing. A string-literal-like-thing already exists for
complex constructions - it's the f-string. The c-string doesn't really
add anything above that.

ChrisA
_______________________________________________
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/BJMDJGWZWVAUL4ZDJLIZ3Y2IBZBKHCHU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to