Hi all, If I want to know whether or not an object bound to the 'context' variable in Python Script has a specific child, how do I do it? For e.g. PScript: get_help(topic): if context.[has_child]('help'): if context.help.[has_child](topic): path = context.help.absolute_url() + '/topic" else: path = None return path Is there a "has_child" function? I tried to do some stuff with traversal but failed miserable (probably didnt understand it well enuff). TIA AM -- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
Hi Aseem, maybe this helps: if 'help' in context.objectIds(): but I think this is slow if there are many objects in a folder, so I use Catalog and something like this: if context.myCatalog({'id': 'help'}): Michal On Mon, Jun 10, 2002 at 12:03:33AM -0700, Aseem Mohanty wrote:
Hi all,
If I want to know whether or not an object bound to the 'context' variable in Python Script has a specific child, how do I do it?
For e.g.
PScript: get_help(topic): if context.[has_child]('help'): if context.help.[has_child](topic): path = context.help.absolute_url() + '/topic" else: path = None return path
Is there a "has_child" function? I tried to do some stuff with traversal but failed miserable (probably didnt understand it well enuff). TIA AM
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
_______________________________________________ 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 Michal, I am still kind of new at Zope so did not use Catalogs. I however found that the " hsattr(container, object) " function seems to work out fine. Had to search in the source for it but found it. I will try the Catalog option and see how it works out. Thanks again, AM Michal Bencur wrote:
Hi Aseem,
maybe this helps:
if 'help' in context.objectIds():
but I think this is slow if there are many objects in a folder, so I use Catalog and something like this:
if context.myCatalog({'id': 'help'}):
Michal
On Mon, Jun 10, 2002 at 12:03:33AM -0700, Aseem Mohanty wrote:
Hi all,
If I want to know whether or not an object bound to the 'context' variable in Python Script has a specific child, how do I do it?
For e.g.
PScript: get_help(topic): if context.[has_child]('help'): if context.help.[has_child](topic): path = context.help.absolute_url() + '/topic" else: path = None return path
Is there a "has_child" function? I tried to do some stuff with traversal but failed miserable (probably didnt understand it well enuff). TIA AM
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
_______________________________________________ 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 )
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
Michal Bencur wrote:
Hi Aseem,
maybe this helps:
if 'help' in context.objectIds():
but I think this is slow if there are many objects in a folder, so I use Catalog and something like this:
Well, it isn't soo slow. objectIds() gets it's information straight from a dictionary, so this is quite fast. OTOH (and perhaps you thought of that), objectValues() is slow compared to objectIds(), because it wakes up every object in that container. If speed is a concern, it might also possible to use a btree folder, but I'm not quite sure if it would help in this situation. cheers, oliver
Hi Oliver, I don't know how Catalog works, but: I believe that using objectIds() cause getting all Ids into array into memory, and when using Catalog, you only access a BTree and don't iterate over all of it's values, but only until Catalog finds object with such id/attribute. because of this using Catalog should require loading less data, less memory required, so it should be faster I guess. I know nothing about internals of Catalog, so fix me if I'm wrong please. Michal
it isn't soo slow.
objectIds() gets it's information straight from a dictionary, so this is quite fast. OTOH (and perhaps you thought of that), objectValues() is slow compared to objectIds(), because it wakes up every object in that container.
Michal Bencur wrote:
Hi Oliver,
I don't know how Catalog works, but:
I believe that using objectIds() cause getting all Ids into array into memory, and when using Catalog, you only access a BTree and don't iterate over all of it's values, but only until Catalog finds object with such id/attribute.
because of this using Catalog should require loading less data, less memory required, so it should be faster I guess.
I know nothing about internals of Catalog, so fix me if I'm wrong please.
Hi Michal, about Zcatalog, ME2 ;-). What I wanted to make clear is that we talked about basically 3 different methods to get infos about subobjects of a Folder - ojectIds(), objectValues or via ZCatalog (ok, there is a forth, btreefolders) You are right that there are performance considerations which have to be done, the question is the quantity of subobjects where these considerations come into play. Just to pull some numbers out of my hat: objectIds(): gives back a list of strings, filtered out from a tuple of dictionaries. Shouldn't give problems for < 1000 objects, and in normal cases not for even more objects IMO (remember, out of my hat). ObjectValues(): gives back a list objects, uses objectIds to find the Ids and "wakes up" the objects pertaining to these Ids. I wouldn't do that for much more than 10 objects without thinking about it. This heavily depends on the circumstances, though. This cleary should be alot slower and memory intensive (and I/O intensive) than objectIds. Zcatalog: well, seems to be most scalable, but again, there's also the Btreefolder. If someone could give better founded number, I'd be glad to hear them. cheers, oliver
Oliver Bleutgen wrote:
If someone could give better founded number, I'd be glad to hear them.
It should be pretty easy to test though. regards Max M -- "Sorry I would Really Like To Help More On This Project, But Am To Busy Doing Paid Work On A Tight Deadline" Max M
Aseem Mohanty writes:
If I want to know whether or not an object bound to the 'context' variable in Python Script has a specific child, how do I do it?
For e.g.
PScript: get_help(topic): if context.[has_child]('help'): if context.help.[has_child](topic): path = context.help.absolute_url() + '/topic" else: path = None return path Search the mailing list archives for "aq_base"...
Dieter
participants (5)
-
Aseem Mohanty -
Dieter Maurer -
Max M -
Michal Bencur -
Oliver Bleutgen