[Zope-dev] Returning a list of names from a Python Method

Steve Alexander steve@cat-box.net
Tue, 19 Sep 2000 11:40:11 +0100


Michael Bernstein wrote:

> Michael Bernstein wrote:
> 
>> Does anyone on the list know how to change the getUserNames
>> Python method to return a list of names instead of a list of
>> objects?
>> 
>> The code in question is this:
>> 
>>   user_ids=self.UserSource.getPersistentItemIDs()
>> 
>>   names=[]
>>   for i in user_ids:
>>       names.append(self.getItem(i))
>>   return names
> 
> 
> Ok, I solved this little problem (and of course it looks
> obvious once I've done it):
> 
>    names=[]
>    for i in user_ids:
>        names.append(i)
>    return names

You can also use the Python map function for this. It will be more 
efficient that iterating through user_ids using "for i in user_ids:"

return map(None, self.UserSource.getPersistentItemIDs())
--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net