Suggested coding style

rantingrick rantingrick at gmail.com
Thu Sep 29 18:56:57 EDT 2011


On Sep 29, 5:12 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Thu, Sep 29, 2011 at 6: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"
>
> Agree that zfill seems to be redundant with str.format, although your
> suggested syntax is atrocious, especially since a syntax already
> exists that fits better in the already-complicated format specifier
> syntax.

It's interesting that you find the format specifier "complicated". I
will admit that upon first glance i lamented the new format method
spec and attempted to cling to the old string interpolation crap.
However, as you use the new format method you will come to appreciate
it. It's an adult beverage with an acquired taste. ;-)

One thing that may help format noobs is to look at the spec as two
parts; the part before the colon and the part after the colon. If you
break it down in this manner the meaning starts to shine through. I
will agree, it is a lot of cryptic info squeezed into a small space
HOWEVER you would no want a verbose format specification.

But i wholeheartedly agree with you points and i would say the zfill
method has no future uses in the stdlib except for historical reasons.
We should deprecate it now.


> "{0:=010d}".format(1234) -> "0000001234"
>
> There are a couple of warts with the existing implementation, however:
>
> 1) str.zfill() operates on strings; the .format() syntax operates on
> numeric types.  I would suggest that the "=" fill alignment in format
> specifiers should be extended to do the same thing as zfill when given
> a string.

EXACTLY!

PS: Has anyone noticed all the off topic chatter about religion and
feelings? Since the main subject of this thread is about zfill i can't
help but wonder if the minions where sent out to present a distraction
with "scripted" pseudo arguments. Just an observation.



More information about the Python-list mailing list