What is the use case for this?Does it have any use case that's not already served by functools.partial?As far as I can tell, this proposal would turn buggy code that currently throws an obvious exception into code that silently does the wrong thing.This seems more appropriate for PHP or JavaScript (or C) than for Python._______________________________________________On Sat, 22 Apr 2023, 06:23 Samuel Muldoon, <muldoonsamuel@gmail.com> wrote:_______________________________________________Consider the following string:x = r"\mathjax{{color}}{{text}}"string `x` contains two parameters named `color` and the other named `text`.Currently, python requires that the string class method `str.format` contain key-word arguments for all parameters, not just one parameterresult = r"\mathjax{{color}}{{text}}".format(color = "blue" , text = "Spanish")result = "\mathjax{blue}{Spanish}"
Can we change str.format so that it is possible to change only one string parameter, but leave the other parameters alone?# pfr is partially_formatted_resultpfr = r"\mathjax{{color}}{{text}}".format(color = "blue") # ERROR! missing parameter `text`
result = r"\mathjax{{color}}{{text}}".format(text = "Spanish") # ERROR! missing parameter `color`The implementation requires fewer than ten lines of code in python, probably less than fifty lines in C, or a different implementation language.
class str:
def format(self, **kwargs):
for key in kwargs:
x = "{"+key+"}"
ostr = kwargs[key].join(self.split(x))
return ostr # output stringAs an example, everywhere a string contained `{text}` it will now say `Spanish` .
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/2A6RTXKQ3LCMKDGDIPOX525O52KYQJS7/
Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/3HHUQV35HQMU6AZWS2NIMFHFEJW3W3LO/
Code of Conduct: http://python.org/psf/codeofconduct/