[Tutor] String format question
andy surany
mongo57a@comcast.net
Wed Nov 27 13:56:45 2002
I think that both of the solutions provided work the same way - but
unfortunately, something is messing up my format - maybe the "map" or
"lambda"??????
I am now using the ljust command which works well if I print a
concatenated string:
a[i]=3D'aaa'.ljust(5)
b[i]=3D'bbb'.ljust(6)
c[i]=3D'ccc'.ljust(5)
print a[i]+b[i]+c[i]
But when I use the map command in my original question, the format is
lost. Am I using the map command incorrectly??? or?????
>
-----Original Message-----
=46rom: Gon=E7alo Rodrigues <op73418@mail.telepac.pt>
To: tutor@python.org <tutor@python.org>
Date: Wednesday, November 27, 2002 1:28 PM
Subject: Re: [Tutor] String format question
>
>----- Original Message -----
>From: "andy surany" <mongo57a@comcast.net>
>To: <tutor@python.org>
>
>
>> 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=3Dmap((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
>>
>
>Check out the string methods ljust, rjust, etc. For example:
>
>>>> print str.ljust.__doc__
>S.ljust(width) -> string
>
>Return S left justified in a string of length width. Padding is
>done using spaces.
>>>> print 'aaa'.ljust(5) + 'bb'.ljust(5) + 'c'.ljust(5)
>aaa bb c
>
>HTH,
>G. Rodrigues
>
>
>_______________________________________________
>Tutor maillist - Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor