Simple - Pretty Printing (pprint) a list with a max width?
rh0dium
steven.klass at gmail.com
Fri Nov 7 10:45:32 EST 2008
Hi all,
Perhaps it's not supposed to work like this but I thought if you
supplied a width to pprint it would nicely format a list to the
width.
KEYS = ['search_keys', 'Section', 'site', 'Employee', 'JobClassCode',
'XBoss', 'Department',
'LocationDesc', 'cn', 'Division', 'Fax', 'SectionCode',
'last_update', 'location',
'mail', 'Nickname', 'JobClass', 'username', 'Name',
'Shift', 'FunctionalArea', 'p4user',
'euid', 'Position', 'DivisionCode', 'OfficePhone',
'CellPhone', 'Supervisor', 'aim',
'url', 'aim_id', 'Assistant', 'DeptNo', 'OtherPhone',
'LocationCode']
pp = pprint.PrettyPrinter(indent=2)
pp.pprint(KEYS)
[ 'search_keys',
'Section',
.
.
That works but it doesn't span the width if you put a width - for that
matter I can't seem to get width to do anything. Anyone else see
that? What I want is to be able to given a list provide a nice fancy
evenly spaced columnar output.
search_keys Section site Employee
JobClassCode XBoss Department LocationDesc
cn Division Fax SectionCode
It's clear pprint does not do this - Does anyone have something for
working with lists to pretty format them?
More information about the Python-list
mailing list