[Tutor] [newbie] output formatting
Eur van Andel
eur at fiwihex.nl
Wed Nov 5 08:26:05 EST 2003
Hi
I'm fairly new to Python (3 days) and I have trouble formatting my output:
> for i in range(1, number_of_boards+1):
> for j in range(1,5):
> print '%2.1f' % T[i][j],
> if i % 3 == 0:
> print '\n',
> time.sleep(5)
produces:
>20.0 19.6 20.0 20.2 9.8 9.8 9.8 9.8 20.0 19.6 20.0 32.8
>18.2 18.2 18.8 19.0 18.4 18.2 19.8 18.8 18.8 18.4 19.0 19.4
>20.0 20.0 20.0 20.2 9.8 9.8 9.8 9.8 20.0 19.6 20.0 32.8
>18.2 18.2 18.8 19.0 18.4 18.0 19.6 18.8 18.8 18.4 19.0 19.4
>20.0 20.0 20.0 20.2 9.8 9.8 9.8 9.8 20.0 19.6 20.0 32.8
Now I would like the 9.8 printed either as 09.8 or with an extra leading space.
Googling for "leading zero", "print output", etc in comp.lang.python gave me
several warnings about leading zeroes for octal numbers.
The tutor section of the manual is too short, the reference too academic (and I
can't find the print statement in the refererence section)
The FAQ mubles about "0":
>0 The conversion will be zero padded for numeric values.
but it doesn't work:
>print '%02.2f, %02.2F'% (T1, T2)
>3.14, 3.14
Life is hard for Python newbies :-(
PS. I'm used to:
>for i = 1 to 10 do
is it really true that I should do
>for i in range(1,10+1)
??
PPS. Is there a Python (or maybe Perl (!)) prog that prints the 'call stack' of
a Python program? I need to analyse other peoples programs, that's why I need
it.
--
Ir. E.E. van Andel, Fine Wire Heat Exchangers, Fiwihex B.V. www.fiwihex.com
Wierdensestraat 74, NL-7604 BK Almelo, The Netherlands eur at fiwihex.nl
phone +31-546-491106 fax +31-546-491107 mobile +31-653-286573
More information about the Tutor
mailing list