Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73534

Format String: Only when value supplied

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'string': 0.09; 'false,': 0.09; 'omit': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'brackets.': 0.16; 'none.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:String': 0.16; 'subject:when': 0.16; 'variable': 0.18; 'replacing': 0.19; 'input': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; '(which': 0.31; 'prints': 0.31; 'question:': 0.31; 'thanks!': 0.32; 'another': 0.32; 'there': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'tell': 0.60; 'florian': 0.84; 'subject:Only': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Florian Lindner <mailinglists@xgm.de>
Subject Format String: Only when value supplied
Date Tue, 24 Jun 2014 11:18:39 +0200
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host lapsgs09.informatik.uni-stuttgart.de
User-Agent KNode/4.13.2
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11211.1403601605.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1403601605 news.xs4all.nl 2853 [2001:888:2000:d::a6]:36747
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73534

Show key headers only | View raw


Hello,

I have a format string like:

 print "{:10} {:25} = {:6}   ({})".format(mod, name, value, description)

description can be None. In this case I want to print an empty string (which 
can be achieved by replacing it with 'description or ""') and I want to omit 
the brackets. Is there a way to tell the format string to omit a part if an 
input variable is None?

Another question: value can be bool. When I format value with just {} if 
prints True or False, when I use {:6} it prints 1 or 0. Is there a way to 
get pack to True / False?

Thanks!
Florian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Format String: Only when value supplied Florian Lindner <mailinglists@xgm.de> - 2014-06-24 11:18 +0200

csiph-web