Python Print help ...
Bill Campbell
linux-sxs at celestial.com
Thu Oct 7 17:42:26 PDT 2010
On Thu, Oct 07, 2010, Andrew Gould wrote:
>On Thu, Oct 7, 2010 at 5:00 PM, Ben Duncan <bend at linux4ms.net> wrote:
>> I am writing some python programs to do various reporting.
>> Is there better ways to do headers and details line then something
>> like:
>>
I frequently do something like this:
headers = ('id', 'field1') # extend as necessary
lenid = 0
# compute max id length
for id in data.keys():
lenid = max(lenid, len(id))
fmt = '%%-%ds %s' % lenid
print fmt % headers
for id in sorted(data.keys()):
print fmt % (id, data[id])
I often use the '%(fieldname)s' construct in formats so things
like ``fmt % dictname'' work making it easier to get data in the
right places.
Bill
--
INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186 Skype: jwccsllc (206) 855-5792
The parasite government is not going to keep growing faster than
the host economy for very much longer; either the economy will
kill the parasite or the parasite will kill the economy. Either
way the parasite will lose its power over the rest of the world.
Bill Walker -- http://www.lewrockwell.com/walker/walker39.1.html
More information about the Linux-users
mailing list