Bill Anderson wrote:
Michael Bernstein wrote:
I *think* I've created a getUserNames python method that returns the appropriate results:
Parameter list: self
Body:
user_ids=self.UserSource.getPersistentItemIDs()
names=[] for i in user_ids: names.append(self.getItem(i)) return names
Returns a list of objects.
I don't understand the differences between the code I pasted above and the code on the original getUserNames method (from :
def getUserNames(self): """Return a list of usernames""" names=self.data.keys() names.sort() return names
Returns a list of usernames.
Can anyone tell me what I need to fix?
Unfortunately, I cannot yet.
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 Thanks, Michael Bernstein
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 Michael Bernstein.
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
participants (2)
-
Michael Bernstein -
Steve Alexander