Dear Barry, >>Using a formatting string of "%10.4f", these would be rendered as: >> >> ' 253.0000' >> ' 77.6000 >> ' 9.0300' >> ' 0.0210' >> >>This formatting gives the impression that all values but the last are >>more precise than they truly are. A scientist or statistician would >>prefer to see something like this: >> >> '254. ' >> ' 77.6 ' >> ' 9.03 ' >> ' 0.0210' >> >>Does numpy or some other math package have that capability?
You can use advanced regexp, called lookaround, lookbehind for this purpose. ############### import re l = (253., 77.6, 9.03, .0210, 1000, 100.1230) ending_zero = re.compile('0(?=0*$)') # zero followed with only zeros for f in l: print re.sub(ending_zero, ' ', ('%10.4f' % f)) ############### Yours sincerely, ______________________________ János Juhász
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor