Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 29th, 2004, 12:08 PM
the_aimbot's Avatar
the_aimbot the_aimbot is offline
PHP ninja
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Melbourne, Australia
Posts: 20 the_aimbot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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??

Reply With Quote
  #2  
Old May 29th, 2004, 12:25 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : May 29th, 2004 at 12:38 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Formatting output

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap