Suggested coding style

rantingrick rantingrick at gmail.com
Thu Sep 29 15:21:36 CEST 2011


On Sep 29, 7:23 am, rantingrick <rantingr... at gmail.com> wrote:

> A specific method for padding a string with ONLY zeros is ludicrous
> and exposes the narrow mindedness of the creator. The only thing worse
> than "zfill" as a string method is making zfill into built-in
> function! The ONLY proper place for zfill is as an option in the
> str.format() method.
>
> py> "{0:zf10}".format(1234) -> "00000000001234"


If something like "zfill" where to be included as a string method, it
should be more general like this:

class String:
    def pad(self, char, count, side='left') => str

py> "".pad(0, 10)
'00000000001234'

However the same can be accomplished with:

py> '{0}1234'.format("0"*10)
'00000000001234'

py> "0"*10+'1234'
'00000000001234'

Seems like pollution either way you go. Best to just let the
programmer handle it. Python IS NOT a 100% OOP language (and for good
reason!) so we don't need methods to scratch every little itch -- and
this itch seems to have originated in the "nether regions" instead of
the "Netherlands".





More information about the Python-list mailing list