|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Formatting output
Is there anyway to neatly for mat output in python so that it lines up in columns??
Code:
def displayUserDetails(myforum):
"This function display the threads in the forum"
list = user.listDetails()
print "ID Occupation First Name Last Name"
for user in list:
print "%s %s %s %s"%(user[0],user[1],user[2],user[3])
The problem i'm having is that the output doesn't line up neatly depending on the the length of the user vars?? |
|
#2
|
||||
|
||||
|
You can do a lot with pythons string formatting options, if all you want to do is justify left or right then you should only have to add a number (min lengh) in between the '%' and 's' and your away!
check this page out of a little more detail: http://www.python.org/doc/current/l...eq-strings.html Code:
>>> #use '-' to justify left.
>>> print '%10s %-7s %15s' % ('never', 'eva', 'ever')
...
Try varying the lengh of the strings at the end and see what happens. Or fire up the Python shell and start playing .Hope this helps, Mark. Last edited by netytan : May 29th, 2004 at 12:38 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Formatting output |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|