Re: Need help with custom string formatter

2022-10-21 Thread Cameron Simpson
On 21Oct2022 16:55, Stefan Ram wrote: I was not aware of "isdigit". There's also "isdecimal" and "isnumeric". They all have subtly different meanings :-) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Need help with custom string formatter

2022-10-21 Thread Cameron Simpson
On 21Oct2022 16:55, Stefan Ram wrote: Robert Latest writes: return super().format_field( value, format_string ) Why do you prefer super().format_field() over plain format()? The doc says: "format_field() simply calls format()." So I figured I might do the same. I am not aware of any

Re: Need help with custom string formatter

2022-10-21 Thread Robert Latest via Python-list
Stefan Ram wrote: [the solution] thanks, right on the spot. I had already figured out that format_field() is the one method I need, and thanks for the str.translate method. I knew that raking seven RE's across the same string HAD to be stupid. Have a nice weekend! --

Need help with custom string formatter

2022-10-21 Thread Robert Latest via Python-list
Hi all, I would like to modify the standard str.format() in a way that when the input field is of type str, there is some character replacement, and the string gets padded or truncated to the given field width. Basically like this: fmt = MagicString('<{s:6}>') print(fmt.format(s='Äußerst'))

Re: Need help with custom string formatter

2022-10-21 Thread Robert Latest via Python-list
Hi Stefan, I have now implemented a version of this, works nicely. I have a few minor questions / remarks: > result += ' ' *( length - len( result )) Nice, I didn't know that one could multiply strings by negative numbers without error. > def __init__( self ): >