What's the use-case for this?

Have you looked into using functools.partial instead?

On Sat, 22 Apr 2023, 06:23 Samuel Muldoon, <muldoonsam...@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* parameter
>
> result = 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_result
>
> pfr    = 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 string
>
> As an example, everywhere a string contained `{text}` it will now say 
> `*Spanish*` .
>
>
> *Samuel Muldoon*
>
> *(720) 653 -2408*
>
> *muldoonsam...@gmail.com <muldoonsam...@gmail.com>*
>
>
>
> _______________________________________________
> 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/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-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/UQV4S22X4X7SF5GAFK4MBRMEPPHJ6P3S/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to