Does anyone know of a way to format text such as adding leading zeros or spacing before or after? 9999 would equal leading zeros to 10 characters = 0000009999 1 Main St would contain spaces up to 20 characters. Is there anyway to do this in Zope?
Hi Sheree, For your numbers: Look up zfill useage something like _.string.zfill(my_string,10) - this fills out leading zeros to 10 characters For strings I am not sure - there is probably some kind of other parameter for zfill as to what character you wish to use hth Laurie -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Beaudette, Sheree Sent: Tuesday, March 19, 2002 3:03 PM To: 'ZOPE@ZOPE.ORG' Subject: [Zope] Formatting a string Does anyone know of a way to format text such as adding leading zeros or spacing before or after? 9999 would equal leading zeros to 10 characters = 0000009999 1 Main St would contain spaces up to 20 characters. Is there anyway to do this in Zope? _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
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.
participants (3)
-
Beaudette, Sheree -
Jud Dagnall -
Laurie Nason