Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-18-2004, 11:05 AM   #1
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
How do I print using format that padded space between printed value ?

root:/home/python_code# ./

I would like to see the column line up straight regardless
of how many characters list[i] has

i subscript,   list[i],     len(list[i]),     len(list)

0              cat                3            3
1              window                6            3
2              idiosyncrasy                12            3


import re
import os
import os.path
import sys
import string

list = ['cat', 'window', 'idiosyncrasy']

print "====================\n"

print "i subscript,   list[i],     len(list[i]),     len(list)\n"

for i in range(len(list)):
   print i, " "*12, list[i], " "*14, len(list[i]), " "*10, len(list)
Old 06-18-2004, 12:14 PM   #2
Senior Member
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
I don't know python so my syntax is probably wrong but something like

offset1 = 14 - len(list[i])
if offset1 > 9
   offset2 = 9
   offset2 = 10

print i, " "*12, list[i], " "*offset1, len(list[i]), " "*offset2, len(list)
Old 06-18-2004, 04:22 PM   #3
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30

Thank you leonscape for your suggestion


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Format & give hdax to free space Rashid Ali Linux - Hardware 6 08-21-2005 03:55 PM
format only gives me less than total space ctrl-a Linux - Newbie 4 10-12-2004 05:15 PM
hi .. how i print screen and save it as jpg or other format? New In Linux 11 Linux - Newbie 4 07-28-2004 06:56 PM
Format ext3 ONLY on unallocated space X-Crawler Linux - General 3 03-16-2004 12:27 PM
perl print double in proper format rajatgarg Programming 1 01-30-2004 01:57 PM

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration