Formatting numbers

Alex alex at somewhere.round.here
Tue Sep 7 20:19:05 EDT 1999


This gets you part of the way:

def format_number(n,l=9):
  output=(n>=0)*' '+repr(n)
  output=output+(l-len(output))*'0'
  return output[:l]

from random import uniform
for i in range(1,31):
  n=uniform(-1000,1000)
  print format_number(n),
  if not(i%3):print

Or maybe you could use the output provided by Numeric arrays.

-- 
If cars were like computers, they would go 300 m.p.h. and get a hundred
miles to the gallon and cost $50. Except that twice a month someone a
thousand miles away would be able to blow up the car, killing everyone
nearby.




More information about the Python-list mailing list