Cameron Simpson writes:
> I would _frequently_ like to be able to provide custom
> conversions. At present I'm using elaborate hacks based on
> __getattr__ etc to recognise things like this:
>
> '{x} is {x_lc} in lowercase'
>
> where the _lc suffix is caught and a value computed from "x".
>
> Custom conversions would let me use this:
>
> '{x} is {x!lc} in lowercase'
I don't understand how this is supposed to work. It looks to me like
!code is a preprocessor:
>>> print(f'{1!a:g}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'g' for object of type 'str'
If so,
'{x} is {x!lc:foo} in lowercase'
will fail because str doesn't implement the 'foo' format code. Do we
really need to extend format() rather than using
def lc(x): return str(x).lower()
'{x} is {lc(x)} in lowercase'
?
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/UEYSD4KKWKMV4PBJAIJS25AAZGXCL3CI/
Code of Conduct: http://python.org/psf/codeofconduct/