FW: [Tutor] String format question

Doug.Shawhan@gecits.ge.com Doug.Shawhan@gecits.ge.com
Wed Nov 27 13:40:19 2002


Forgot to include the list...

-----Original Message-----
From: Shawhan, Doug (CAP, ITS, US) 
Sent: Wednesday, November 27, 2002 12:36 PM
To: 'andy surany'
Subject: RE: [Tutor] String format question


This is ugly, but it works...


>>> import string
>>> l=['one, two, three', '001, 002, 003', '1, 2, 3']
>>> for each in l:
	l2=string.split(each,',')
	print string.ljust(l2[0], 10), string.center(l2[1], 10),\
	      string.rjust(l2[2], 10)+'\n'

	
one            two         three

001            002           003

1               2              3

>>> 

-----Original Message-----
From: andy surany [mailto:mongo57a@comcast.net]
Sent: Wednesday, November 27, 2002 12:21 PM
To: tutor@python.org
Subject: [Tutor] String format question


Hello list,

I am concatenating a series of string elements for display to a scrolled
list. The code is working fine - but the result is not as user friendly
as I would like. This is what I'm doing:

# The individual contents of a,b, & c can be variable lengths.
#
# Now I use "map" to concatenate the individual records
options=map((lambda i: a[i]+b[i]+c[i]),range(nrecs)
self.ScrolledList(options) # This function populates the list.

This is what the output looks like:

aaa bbb ccc
aaa bb ccccc
a b c

Now what I would like is:

aaa  bbb  ccc
aaa  bb    ccccc
a      b     c

(i.e.: aligned columns)

How can/should I do this?

TIA.

-Andy


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor