Chris, I was not suggesting it for Python as one of many possible implementations.
I do see perfectly valid uses in other contexts. For example, if I have a program that displays my text as pixels in some font and size, I may indeed want the text clipped at 2 1/2 repetitions. But as always, when there are choices to be made, you have to very clearly document the choice or offer ways to do it another way. In a non-fixed-width font, 2.5 may mean knowing how many pixels and adjusting so that a narrow letter "i" may be shown in one font and not another, for example. If you want completeness, sure, you can define fractional parts of a string in this context by the percentage of CHARACTERS in it. But as we have often seen, in other encodings you need to differentiate between varying numbers of bytes versus the underlying symbols they represent. Your example from the Pike language not only supports the multiplication of a string but division and mod. Python currently does not allow those. So why not extend it to allow complex numbers? >>> "Hello" * complex(5,0) TypeError: can't multiply sequence by non-int of type 'complex' >>> "Hello" * complex(0,5) TypeError: can't multiply sequence by non-int of type 'complex' The first one above is actually perfectly valid in the sense that the real part is 5 and there is no imaginary component. With a bit of effort, I can use the complexity to work: >>> "Hello" * int(complex(5,0).real) 'HelloHelloHelloHelloHello' Let me reiterate. There are languages that do all kinds of interesting things and some of what Python has done is seen by others as interesting. They regularly borrow from each other or use parts and innovate further. I have no serious objection to making well-thought-out changes if they are determined to be not only useful, but of higher priority than a long shopping list of other requests. I am wary of overly bloating a language by placing too many things in the core. It strikes me as doable to create a module that encapsulates a feature like this in a limited way. What may be needed is just a carefully constructed class that starts off as similar to str and adds some methods. Any user wanting to use the new feature would either start using the new class directly or cast their str to it when they want it to be useable. But the good news is that I am nowhere in the python hierarchy and have no ability to make any changes. This is purely academic for me. And, if I want such features and see tons of existing ways to get what I want or can roll it for myself, ... -----Original Message----- From: Python-list <python-list-bounces+avi.e.gross=gmail....@python.org> On Behalf Of Chris Angelico Sent: Thursday, April 13, 2023 3:02 AM To: python-list@python.org Subject: Re: Weak Type Ability for Python On Thu, 13 Apr 2023 at 15:40, <avi.e.gr...@gmail.com> wrote: > And, no, I do not suggest 2.5 be interpreted as putting in an > approximate percentage so that .8 * "Hello" should result in "Hell" ... $ pike Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend) Ok. > "Hello, world! " * 2.5; (1) Result: "Hello, world! Hello, world! Hello, " > "Hello, world! Hello, world! Hello, " / 10; (2) Result: ({ /* 3 elements */ "Hello, wor", "ld! Hello,", " world! He" }) > "Hello, world! Hello, world! Hello, " % 10; (3) Result: "llo, " > "Hello, world! Hello, world! Hello, " / 10.0; (4) Result: ({ /* 4 elements */ "Hello, wor", "ld! Hello,", " world! He", "llo, " }) > Multiplying and dividing strings by floats makes perfect sense. (The ({ }) notation is Pike's array literal syntax; consider it equivalent to Python's square brackets for a list.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list