printing columns question

Emile van Sebille emile at fenx.com
Sat Mar 24 22:51:57 EST 2001


from:
http://starship.python.net/quick-ref1_52.html#Statements

Format operator for strings (%)
Uses C printf format codes :

Supports: %, c, s, i, d, u, o, x, X, e, E, f, g, G.
Width and precision may be a * to specify that an integer argument specifies
the actual width or precision.

The flag characters -, +, blank, # and 0 are understood.

%s will convert any type argument to string (uses str() function)

        a = '%s has %03d quote types.' % ('Python', 2)
        a ==> 'Python has 002 quote types.'
Right-hand-side can be a mapping:
        a = '%(lang)s has %(c)03d quote types.' % {'c':2, 'lang':'Python}
(vars() function very handy to use on right-hand-side.)


For a further description of c's printf, look at
http://www.rt.com/man/printf.3.html

Maybe somebody knows of a better single link.

HTH.

--

Emile van Sebille
emile at fenx.com

---------
"Victor Louie" <vlouie at telusplanet.net> wrote in message
news:PXbv6.52892$Lm2.6031361 at news0.telusplanet.net...
> Hi,
>
> Just looking at some sample code...
>
>         for i in trip[dest][1][1:] :
>             print '\t%-15s%-15s%4d' % (prev, i, citymap[prev][i][0]),
>             print '%5d:%02d' % (citymap[prev][i][1], citymap[prev][i][2])
>             prev = i
>         print "\t-------------------------------------------"
>         print '\t%-30s%4d' % ("total:", trip[dest][0][0]),
>         h = trip[dest][0][1] + trip[dest][0][2] / 60
>         m = trip[dest][0][2] % 60
>         print '%5d:%02d' % (h, m)
>
> ...i was just wondering if anybody could explain to me how the print
> worked...
>     ie. print '\t%-15s%-15s%4d' % (prev, i, citymap[prev][i][0]),
>
> I understand that \t is a tab....but i don't get anything after that
>
> If anyone could help it would be great.
>
> Thanks
> Victor
>
>
>





More information about the Python-list mailing list