What F strings should have been
D'Arcy Cain
darcy at VybeNetworks.com
Thu Feb 15 05:51:43 EST 2018
On 02/15/18 02:56, Peter Otten wrote:
>> class FSTR(str):
>> def __call__(self, *args):
>> return self.format(*args)
>>
>> And here is how it could be used.
>>
>> s = FSTR("ABC {1} {0} {2[x]}")
>
> This can be simplified to
>
> s = "ABC {1} {0} {2[x]}".format
Hmm. Hadn't thought of that.
>> print(s(1, 2, dict(x=3)))
>>
>> Too bad that it is too late to assign f'' to that function.
>
> I must be missing something. How would you simplify or improve the
> readability of the above with your version of f"..."?
s = f"ABC {1} {0} {2[x]}"
--
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com
More information about the Python-list
mailing list