[Zope] Python Script Question

Michael A. Ruberto michael at dortronics.com
Fri May 14 16:36:49 EDT 2004


Laura,

a nice method would be to trap for only certain object types. This way you
can exclude Python Scripts altogether but count everything else. e.g.

for object in context.objectValues(['Folder', 'DTML Document', 'File']):

in this case it will just trap for Folders, DTML Documents and Files.
obviously, it's not helpful to you if you want to trap everything but
itself, *including* other Python Scripts...
so we can just trap for the offending Id before adding to "success".

I named this script itemCount

success = 0
offending_Id = "itemCount"
for item in context.objectValues():
	b = item.getId()
     	if b.find (offending_Id) > -1:
          success = success - 1
	else:
          success = success + 1

return success

it works fine. just keep in mind if your folder has 6 items plus this script
it will return 5.

good luck

Michael Ruberto
DORTRONICS SYSTEMS INC.

-----Original Message-----
From: zope-bounces at zope.org [mailto:zope-bounces at zope.org]On Behalf Of
Laura McCord
Sent: Friday, May 14, 2004 12:54 PM
To: zope at zope.org
Subject: [Zope] Python Script Question


I am starting out with this in my script

RESPONSE = context.REQUEST.RESPONSE
success = 0
for id in context.objectIds():
   success = success + 1
return success


All this does is count the contents in the folder. However, how do you
specify what content to count. For instance, I do not want this script
to count itself in the folder contents but I want it to include
everything else. Any suggestions?

Thanks,
 Laura

_______________________________________________
Zope maillist  -  Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )




More information about the Zope mailing list