In a project of mine, I'm passing strings to a Formatter subclass whic formats it using the format specifier mini-language. In my case it is customized (using the features of the Formatter class) by adding additional bang converters : !u converts the resulting string to lowercase, !c to titlecase, !q doubles any square bracket (because reasons), and some others.
For example, using a = "toFu"
, "{a!c}"
becomes "Tofu"
How could I make my system use f-string syntax, so I can have "{a+a!c}"
be turned into "Tofutofu"
?
NB: I'm not asking for a way of making f"{a+a!c}"
(note the presence of an f
) resolve itself as "Tofutofu"
, which is what hook into the builtin python f-string format machinery covers, I'm asking if there is a way for a function or any form of python code to turn "{a+a!c}"
(note the absence of an f
) into "Tofutofu"
.