Help Required

Surajsub surajsub at netscape.net
Mon Mar 18 12:55:18 EST 2002


Chris Liechti <cliechti at gmx.net> wrote in message news:<Xns91D31A8FD3696cliechtigmxnet at 62.2.16.82>...
> 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

Ok here is the code..I just need a set of uid's and other similar
parameters which i need to feed to ldap.these are just a dummy set of
values.
=============================================================
#!/usr/local/bin/python
import string

MIN=0
MAX=25
UID="UID"
val=""
for x in range(MIN,MAX,1):
    if( x == 0 ):
        x=str(x)
        val=UID,x+','
        st=string.join(val,"")
        st=string.strip(st)
        print st,
    elif(x > 0 ):
        x=str(x)
        val='UID'+x+',',
        st=string.replace(string.join(val,""),' ','')
        print st,
==========================================================

The output that this script produces is 

UID0, UID1, UID2, UID3, UID4, UID5, UID6, UID7, UID8, UID9, UID10,
UID11, UID12, UID13, UID14, UID15, UID16, UID17, UID18, UID19, UID20,
UID21, UID22, UID23, UID24,


Notice the spaces between the , and the UID
============================================
I need to get rid of these spaces.How do i do it..

Thanks



More information about the Python-list mailing list