How to show all keys for items that I get in a catalog search?

links = self.catalog(portal_path='Link')
for link in links:
    for value in link:
        print value

With this code I can show all values, but I don't know how to show the keys.

有帮助吗?

解决方案

The ZCatalog does not return dictionaries. It returns a sequence of result objects (called Catalog Brains, because you can give them smarts. Long historical story).

So you loop over them, and each object has attributes for each metadata column you defined in the catalog:

links = self.catalog(portal_path='Link')
for link in links:
    print link.Title

If you need to dynamically loop over the available attributes, use .schema() for the keys:

for link in links:
    for key in link.schema():
        print link[attr]

其他提示

I found this:

for link in links: link.schema()

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top