On 07/03/2023 07:26, Stephen J. Turnbull wrote:
Rob Cliffe writes:
> Perhaps where you're not laying out a table,
I'm an economist
Oh goody! *Please* tell me what our Government needs to do to grow the
UK economy and curb inflation. I'll inform my MP immediately. 😁
Seriously though ...
, laying out tables is what I do. :-) Getting
serious:
> but constructing a human-readable string? So
> s1 + ' ' + s2 + ' ' + s3
> or
> ' '.join((s1, s3, s3))
> would become
> s1 & s2 & s3
> saving you a bit of typing. Just sayin'.
str '+' has long been quite rare in my coding. str concatenation is
almost never in an inner loop, or slighly more complex formatting is
the point. f-strings and .format save you the type conversion to str.
So I don't find that occasional saving at all interesting. A
vanishingly small number of my str constructions involve only strs
with trivial formatting.
What interests me about the proposal is the space-collapsing part,
which a naive f-string would do incorrectly if, say, s2 == '' or s3 ==
'\t\t\ttabs to the left of me'. But where does this space-surrounded
str data come from?
I would say: Very often in real-life cases it doesn't. So using '&'
would be equivalent to stripping the strings and applying ' '.join().
And more concise, and IMHO more readable (albeit, as Mr Berlier
helpfully informs us, less efficient 😁).
But I can imagine cases where the leftmost string starts with
indentation to start a paragraph (or to correctly indent Python code),
which you want to preserve.
Or perhaps even to make it start in the correct column of a table, ha-ha.
As for trailing whitespace in the rightmost string ... Hm, I can't think
of a use case ATM. I just thought it would be nice to make the
operation symmetrical. s1 & s2 *could* be defined as equivalent to
(s1.rstrip() + ' ' + s2.lstrip()).rstrip()
(and it would still be associative). Would this be practicality beating
purity, or a hideous symmetry breaking?
I didn't highlight it before, so let me take the opportunity now: One of
the examples I listed shows another use case: constructing an operating
system command and ensuring that the parameters are separated by (at
least) one space. Bear with me while I repeat it:
Lib\site-packages\numpy\distutils\system_info.py:2677:
cmd = config_exe + ' ' + self.append_config_exe + ' ' + option
cmd = config_exe & self.append_config_exe & option
Best wishes
Rob Cliffe
Steve
_______________________________________________
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/NXY5PATRDIZEHO4CUUAS6AYA2NZRZH3E/
Code of Conduct: http://python.org/psf/codeofconduct/