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


Groups > comp.lang.python > #73534 > unrolled thread

Format String: Only when value supplied

Started byFlorian Lindner <mailinglists@xgm.de>
First post2014-06-24 11:18 +0200
Last post2014-06-24 11:18 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#73534 — Format String: Only when value supplied

FromFlorian Lindner <mailinglists@xgm.de>
Date2014-06-24 11:18 +0200
SubjectFormat String: Only when value supplied
Message-ID<mailman.11211.1403601605.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web