On Wed, Mar 27, 2013 at 2:50 AM, <c...@isbd.net> wrote: > What's a neat way to print columns of numbers with blanks where a number > is zero or None? > > E.g. I want to output something like:- > > Credit Debit Description > 100.00 Initial balance > 123.45 Payment for cabbages > 202.00 Telephone bill > > > For each line I have either the credit or the debit amount and the other > is 0 or None. However you can't get number formatting (old or new) to > output a blank for 0 and it barfs on None.
Try printing out this expression: "%.2f"%value if value else '' Without the rest of your code I can't tell you how to plug that in, but a ternary expression is a good fit here. ChrisA -- http://mail.python.org/mailman/listinfo/python-list