LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 06-18-2004, 10:05 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

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


root:/home/python_code# ./range_and_len.py

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


Code:
=============================
i subscript,   list[i],     len(list[i]),     len(list)

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


#!/usr/bin/python

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, 11:14 AM   #2
leonscape
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

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

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

Original Poster
Rep: Reputation: 30
reply

Thank you leonscape for your suggestion
 
  


Reply


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 02:55 PM
format only gives me less than total space ctrl-a Linux - Newbie 4 10-12-2004 04: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 05:56 PM
Format ext3 ONLY on unallocated space X-Crawler Linux - General 3 03-16-2004 11:27 AM
perl print double in proper format rajatgarg Programming 1 01-30-2004 12:57 PM


All times are GMT -5. The time now is 08:00 PM.

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