Iterating through object properties
Is there a way either in DTML or a python script to iterate through all of the properties of an object without knowing its specific type? For example, if I have CMF Types of Document, File, Event, etc. I want to build a list of all of their properties without knowledge of the particular type. Ideas? Thanks, Kevin
See "module PropertyManager" of http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixB.stx -aj ----- Original Message ----- From: "Kevin Carlson" <khcarlso@bellsouth.net> To: <zope@zope.org> Sent: Monday, August 26, 2002 18:27 Subject: [Zope] Iterating through object properties
Is there a way either in DTML or a python script to iterate through all of the properties of an object without knowing its specific type? For example, if I have CMF Types of Document, File, Event, etc. I want to build a list of all of their properties without knowledge of the particular type. Ideas?
Thanks,
Kevin
_______________________________________________ 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 )
Thanks, Andreas. This works great for properties that are defined in Zope. Is there a way to do this same thing for properties that are defined in a python product? For example, calling propertyItems on a CMFEvent displays the title of the event, but does not display the start_date and end_date properties that are defined in the python source for the CMF type. Ideas? Kevin -----Original Message----- From: Andreas Jung [mailto:lists@andreas-jung.com] Sent: Monday, August 26, 2002 12:28 PM To: Kevin Carlson; zope@zope.org Subject: Re: [Zope] Iterating through object properties See "module PropertyManager" of http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixB.stx -aj ----- Original Message ----- From: "Kevin Carlson" <khcarlso@bellsouth.net> To: <zope@zope.org> Sent: Monday, August 26, 2002 18:27 Subject: [Zope] Iterating through object properties
Is there a way either in DTML or a python script to iterate through all of the properties of an object without knowing its specific type? For example, if I have CMF Types of Document, File, Event, etc. I want to build a list of all of their properties without knowledge of the particular type. Ideas?
Thanks,
Kevin
_______________________________________________ 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 )
Kevin Carlson wrote:
Thanks, Andreas. This works great for properties that are defined in Zope. Is there a way to do this same thing for properties that are defined in a python product? For example, calling propertyItems on a CMFEvent displays the title of the event, but does not display the start_date and end_date properties that are defined in the python source for the CMF type.
Perhaps you can use the dir() function to get a list of attributes. Something like: attributes = [attr for attr in dir(obj.aq_base) if not callable(getattr(obj.aq_base, attr))] regards Max M "klaatu verata niktu"
It looks like the "dir" function will do what I need it to do, but I'm curious about something: I can't seem to call this function inside a Python script. Do I have to use an external method for this function? If so, why? It's a python built-in and other built-in functions allow calling from python scripts... Thanks, Kevin -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Max M Sent: Monday, August 26, 2002 4:19 PM To: Kevin Carlson Cc: zope@zope.org Subject: Re: [Zope] Iterating through object properties Kevin Carlson wrote:
Thanks, Andreas. This works great for properties that are defined in Zope. Is there a way to do this same thing for properties that are defined in a python product? For example, calling propertyItems on a CMFEvent displays the title of the event, but does not display the start_date and end_date properties that are defined in the python source for the CMF type.
Perhaps you can use the dir() function to get a list of attributes. Something like: attributes = [attr for attr in dir(obj.aq_base) if not callable(getattr(obj.aq_base, attr))] regards Max M "klaatu verata niktu" _______________________________________________ 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 )
On Tue, Aug 27, 2002 at 09:41:55AM -0400, Kevin Carlson wrote:
It looks like the "dir" function will do what I need it to do, but I'm curious about something: I can't seem to call this function inside a Python script. Do I have to use an external method for this function? If so, why? It's a python built-in and other built-in functions allow calling from python scripts...
Read the Zope book sections on python scripts: they have strict security restrictions on what can be imported. External methods do not. --PW - Paul Winkler "Welcome to Muppet Labs, where the future is made - today!"
participants (4)
-
Andreas Jung -
Kevin Carlson -
Max M -
Paul Winkler