[Zope] Formatting a string
Jud Dagnall
jdagnall@sgi.com
Tue, 19 Mar 2002 14:06:40 -0800
> Does anyone know of a way to format text such as adding leading zeros
> or spacing before or after?
You can use the python print command, which takes printf-style
formatting instructions.
my_integer=10
my_string="hello"
print "%09d" % my_integer
print "% 9s" % my_string
Output is:
000000010
hello
Here's a link to some printf examples, although you can do "man printf"
if you're on a unix-like system to get a more detailed explanation of
how printf works.
http://www.harper.cc.il.us/bus-ss/cis/166/mmckenzi/lect05/l05d.htm
Here's a link to an older python quick-reference
http://starship.python.net/quick-ref1_52.html - search for printf on the
page.