[Zope] returning ids from objectValues in External Method
Jim Fulton
jim@digicool.com
Tue, 14 Dec 1999 15:39:00 +0000
JP Glutting wrote:
>
> I have a question that has *got* to have a simple answer, but I canīt seem to
> figure it out. I am trying to return a list of ids from an External Method,
> after they have been sorted and selected according to some simple search
> criteria.
>
> The code looks something like this (stripped down to the basics):
>
> idList=[]
> for OB in self.objectValues(
> idList.append(getattr(OB, 'id')
> return idList
>
> And I get back a list of empty items (or empty strings with repr(getattr(OB,
> 'id')) - [,,,,,,] or ['','','','',''], respectively.
>
> I can get any other attribute (title, etc.), but not the id.
The id attribute on a DTML document or method is a method.
When you convert it to a string, you get something like:
<Python Method object at 842ca20>
which looks like a non-standard HTML element and is
not shown by a browser. I bet that if you viewed the
document source, you'd see this.
You could do something like:
idList=[]
for OB in self.objectValues('HTML Document'):
id=getattr(OB, 'id')
if type(id) is not type(''): id=id()
idList.append(id)
return idList
Then again, you could just call:
objectIds('DTML Document')
Jim
--
Jim Fulton mailto:jim@digicool.com
Technical Director (888) 344-4332 Python Powered!
Digital Creations http://www.digicool.com http://www.python.org
Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission. Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.