objectValues return value
I wrote a script the returns a list object of all title_or_id values of objects in a folder. The problem is when there are no objects in the folder. The script should return a list contianing the string 'none'.. but doesn't. In fact, the script seems to either hang or have no return value... Any pointers? # returns a python list contained the title of the page templates in this folder list = context.objectValues('Page Template') if list == None: return ['none'] newlist = [] for zpt in list: newlist.append(zpt.title_or_id()) return newlist -- David Bear College of Public Programs/ASU Mail Code 0803
On Wed, Dec 04, 2002 at 10:17:56AM -0700, David Bear wrote:
I wrote a script the returns a list object of all title_or_id values of objects in a folder. The problem is when there are no objects in the folder. The script should return a list contianing the string 'none'.. but doesn't. In fact, the script seems to either hang or have no return value...
Any pointers?
# returns a python list contained the title of the page templates in this folder list = context.objectValues('Page Template') if list == None: return ['none']
Nope... objectValues always returns a list. Why do you expect it to return None? Change that to: if list == []: return ['none'] -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
I wrote a script the returns a list object of all title_or_id values of objects in a folder. The problem is when there are no objects in the folder. The script should return a list contianing the string 'none'.. but doesn't. In fact, the script seems to either hang or have no return value...
Any pointers?
# returns a python list contained the title of the page templates in this folder list = context.objectValues('Page Template') if list == None: return ['none'] newlist = [] for zpt in list: newlist.append(zpt.title_or_id()) return newlist
The objectValues method should return an empty list if the collection is empty, not None. Try: list = context.objectValues('Page Template') if not list: return ['none']
Hi David, --On Mittwoch, 4. Dezember 2002 10:17 -0700 David Bear <David.Bear@asu.edu> wrote:
I wrote a script the returns a list object of all title_or_id values of objects in a folder. The problem is when there are no objects in the folder. The script should return a list contianing the string 'none'.. but doesn't. In fact, the script seems to either hang or have no return value...
Any pointers?
the method is designed to return a list, so if no objects are in - the list is empty. An empty list is not None! return [zpt.title_or_id() for zpt in context.objectValues('Page Template')] or 'none' would do the job. But I dont think its very usefull to return different datatype (list vs. string) on different conditions. What do you want to do with the result after that? Regards Tino
# returns a python list contained the title of the page templates in this # folder list = context.objectValues('Page Template') if list == None: return ['none'] newlist = [] for zpt in list: newlist.append(zpt.title_or_id()) return newlist
--
David Bear College of Public Programs/ASU Mail Code 0803
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (4)
-
Brian Lloyd -
David Bear -
Paul Winkler -
Tino Wildenhain