Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41916
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.025 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'expression:': 0.09; 'formatting': 0.09; 'plug': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'subject:number': 0.09; 'columns': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'none.': 0.16; 'ternary': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'subject:need': 0.19; 'fit': 0.20; 'print': 0.22; 'initial': 0.24; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'received:209.85.220.174': 0.31; "can't": 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'received:209': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'bill': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'blank': 0.60; 'expression': 0.60; 'tell': 0.60; 'balance': 0.61; 'numbers': 0.61; 'telephone': 0.63; 'mar': 0.68; 'subject:nothing': 0.84; 'debit': 0.91; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=iUPtZS9kxc6jK+eYbadz1WFvNs4MIspUQQKfSnUd5hg=; b=HwK4oLcre1YF+/8zrIQ7WLr8KRIKcv3W5RjAkpO7Tw+OJ4kvAf5A/rKheccEDgUnB3 k3rfbsJJroVa+sBpTMyjlB8MW4ItvTTu4zeuqReBulF3QsA61NNXQWFxfsacBUd/7BTK 8KuGUKMgPTmCtbKCK3A6M4OG6Z0CRLLcJW8t0AefFiNx2VXyU6Yya0rrK0KNI8g7IaOa 8b1BrYbINH6wZLoC0EkTyxtQ7iOmf1xS3UK48jNA4HUuwOMWHg34Gv7mygE1R7P8wGgy eTexMdVi5i9lrx310VwEIdzNC92+z6aDWN+Uq7WoxkY6Ja+TwGbnYwJYTKJ3hvk0G/e1 3ldA== |
| MIME-Version | 1.0 |
| X-Received | by 10.58.56.161 with SMTP id b1mr19846033veq.42.1364314097097; Tue, 26 Mar 2013 09:08:17 -0700 (PDT) |
| In-Reply-To | <jms82a-6sl.ln1@chris.zbmc.eu> |
| References | <jms82a-6sl.ln1@chris.zbmc.eu> |
| Date | Wed, 27 Mar 2013 03:08:16 +1100 |
| Subject | Re: I need a neat way to print nothing or a number |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3753.1364314099.2939.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364314099 news.xs4all.nl 6968 [2001:888:2000:d::a6]:41816 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41916 |
Show key headers only | View raw
On Wed, Mar 27, 2013 at 2:50 AM, <cl@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
I need a neat way to print nothing or a number cl@isbd.net - 2013-03-26 15:50 +0000 Re: I need a neat way to print nothing or a number Chris Angelico <rosuav@gmail.com> - 2013-03-27 03:08 +1100 Re: I need a neat way to print nothing or a number John Gordon <gordon@panix.com> - 2013-03-26 16:29 +0000 Re: I need a neat way to print nothing or a number Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-26 17:06 +0000 Re: I need a neat way to print nothing or a number Chris Angelico <rosuav@gmail.com> - 2013-03-27 04:14 +1100 Re: I need a neat way to print nothing or a number Peter Otten <__peter__@web.de> - 2013-03-26 18:22 +0100 Re: I need a neat way to print nothing or a number Ethan Furman <ethan@stoneleaf.us> - 2013-03-26 10:21 -0700 Re: I need a neat way to print nothing or a number Chris Angelico <rosuav@gmail.com> - 2013-03-27 05:48 +1100 Re: I need a neat way to print nothing or a number Tony the Tiger <tony@tiger.invalid> - 2013-03-27 01:11 -0500 Re: I need a neat way to print nothing or a number Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-27 08:23 +0000
csiph-web