[Zope] Python script sort by id
Tim Hicks
tim@sitefusion.co.uk
Sat, 28 Jul 2001 01:05:26 +0100
----- Original Message -----
From: "Dieter Maurer" <dieter@handshake.de>
To: "Tim Hicks" <tim@sitefusion.co.uk>
Cc: <zope@zope.org>
Sent: Friday, July 27, 2001 8:21 PM
Subject: Re: [Zope] Python script sort by id
> Tim Hicks writes:
> > I have a slightly strange problem with sorting in a python script.
> > Basically, sorting by title and meta_type both work as expected, but by
id produces totally random results that I cannot fathom (I really can't see
any pattern at all).
> You know, that "id" is often a method and not an attribute.
> If it is, your comparisons will produce funny results.
>
> Use "getID()" instead.
def sort_id(ob1, ob2):
return cmp(ob1.getID(), ob2.getID())
Thanks Dieter, but with this, I get...
"""
Error Type: AttributeError
Error Value: getID
Traceback (innermost last):
File /mnt2/local/Zope-2.3.2-src/lib/python/ZPublisher/Publish.py, line
223, in publish_module
File /mnt2/local/Zope-2.3.2-src/lib/python/ZPublisher/Publish.py, line
187, in publish
File /mnt2/local/Zope-2.3.2-src/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
(Object: Traversable)
File /mnt2/local/Zope-2.3.2-src/lib/python/ZPublisher/Publish.py, line
171, in publish
File /mnt2/local/Zope-2.3.2-src/lib/python/ZPublisher/mapply.py, line 160,
in mapply
(Object: index_html)
File /mnt2/local/Zope-2.3.2-src/lib/python/ZPublisher/Publish.py, line
112, in call_object
(Object: index_html)
File /mnt2/local/Zope-2.3.2-src/lib/python/Shared/DC/Scripts/Bindings.py,
line 324, in __call__
(Object: index_html)
File /mnt2/local/Zope-2.3.2-src/lib/python/Shared/DC/Scripts/Bindings.py,
line 354, in _bindAndExec
(Object: index_html)
File
/mnt2/local/Zope-2.3.2-src/lib/python/Products/PythonScripts/PythonScript.py
, line 336, in _exec
(Object: index_html)
(Info: ({'script': <PythonScript instance at 99beb0>, 'context':
<Folder instance at 99c478>, 'container': <Folder instance at
832438>, 'traverse_subpath': []}, (), {}, None))
File Script (Python), line 121, in index_html
(Object: string)
File <string>, line 40, in sort_id
(Object: Traversable)
File
/mnt2/local/Zope-2.3.2-src/lib/python/Products/PythonScripts/Guarded.py,
line 273, in __getattr__
File
/mnt2/local/Zope-2.3.2-src/lib/python/Products/PythonScripts/Guarded.py,
line 143, in __careful_getattr__
(Object: Traversable)
AttributeError: (see above)
"""
It seems that the cmp function needs to get hold of attributes, not methods.
Even if I specifically call a method on ob1 or ob2, getattr seems to be
called in there somewhere.
Any more clues?
tim