Help Required

Chris Liechti cliechti at gmx.net
Fri Mar 15 20:35:59 EST 2002


surajsub at netscape.net (Surajsub) wrote in 
news:cf4a8ef1.0203151724.440b67ac at posting.google.com:
> Hi,
> I am a newbie to Python and am pretty fascinated by it power and
> speed.

Welcome

>I am however puzzled in trying to write this script.
> The script builds a list of userids to be fed to ldap and it is
> supposed to be
> 
> uid1,uid2,uid3....and so on.( Notice there is no space)
> 
> However when i am trying to create the uid list it gives
> 
> uid1, uid2, uid3,...and so on.
> how do i get rid of this leading space if u would call it..
> string.lstrip does not work either.

i don't see what you're doing. please post some example code alomg 
with such questions. however some guesses:

if you have a list of numbers: n = [1,2,3,4]
you can make string of it using: ','.join(map(str,n))

or are you parsing the numbers from a string? then you could try:
>>> import string
>>> n = map(string.strip, '1, 2, 3, 4'.split(','))

and if want numbers instead of strings in the list:
>>> n = map(int, '1, 2, 3, 4'.split(','))

(*) "map" is simply calling the 1st argument (a function) with each 
element of the list 2nd arg and saves the result in a list which it 
returns.
you can achieve the same with a "for" loop over the list and saving 
the result in an other list, but i find the "map" is very elegant.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list