Need help with custom string formatter

Robert Latest boblatest at yahoo.com
Fri Oct 21 12:37:23 EDT 2022


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 ):
>         super().__init__()

Isn't this a no-op? Probably a leftover from my stuff.

>     def format_field( self, value, format_string ):
>         if re.match( r'\d+', format_string )and type( value )== str:

Why do you prefer re.match(r'\d+', x) over x.isdigit()?

>             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.

Thanks!


More information about the Python-list mailing list