[Tutor] A file containing a string of 1 billion random digits.

Steven D'Aprano steve at pearwood.info
Mon Jul 19 17:01:58 CEST 2010


On Tue, 20 Jul 2010 12:48:13 am Richard D. Moores wrote:
> On Mon, Jul 19, 2010 at 07:14, ALAN GAULD <alan.gauld at btinternet.com> 
wrote:
> >> 4 and executed many times. Seems the 0 in 0dddd is
> >> there when a dddd is a 3-digit number such as 123.
> >> In that case a zero is prefixed to 123 to produce
> >> 0123. Or if just 23, 2 zeros are prefixed, etc.
> >> Correct?
> >
> > Yes, the zero indicates that the string should be padded
> > with zeros to the length specified. The format string
> > documentation gives all the details
>
> I've been unable to find any mention of that use of the asterisk in
> the 3.1 docs, in
>
> http://docs.python.org/py3k/library/string.html#formatspec
>
> or
>
> http://docs.python.org/py3k/library/string.html#formatstrings
>
> Suggestion?

You're looking in the wrong place. This is not part of format strings, 
as it doesn't use the str.format() method. It uses the % string 
interpolation operator.

http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting-operations


You can get the same result with the format mini-language. See the 
example "Nested arguments and more complex examples" just before the 
section on Template Strings here:

http://docs.python.org/py3k/library/string.html#format-specification-mini-language




-- 
Steven D'Aprano


More information about the Tutor mailing list