Help Required

Chris Liechti cliechti at gmx.net
Mon Mar 18 16:21:54 EST 2002


surajsub at netscape.net (Surajsub) wrote in
news:cf4a8ef1.0203180955.55313155 at posting.google.com: 
> 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: 
> 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):

1 is the default step, you don't need to write it explicit.

>     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
> 

that's because you use "print x," the coma does it... either use 
sys.stdout.write() or prepeare the entire string and print it later 
i.e. store all your ids and join the list afetwards.

uids = []
for x in range(MIN,MAX):
    	uids.append("UID%d" % x)
print ','.join(uids)

or with map & lambda:
print ','.join(map(lambda x, "UID%d", range(MIN,MAX)))

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list