Properties of File objects in python script
Hi, the Zope Book says that I can check properties of objects via if object.hasProperty('siteMap') and object.siteMap: results.append(object) for instance. I just added a property 'dynscript' with the type String to some File objects and wanted to do some action if a File object just has such a property. So I did: name = "<some parameter of the script>" cont = container.content for file in cont.objectValues('File'): if name == file.getId(): foundname=name foundfile=file break if foundfile.hasProperty('dynscript') : return foundname.dynscript --> Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: dynscript Could anybody enlighten my why the example from the Zope book does not apply for my application? Kind regards Andreas.
On Wed, Nov 13, 2002 at 03:50:44PM +0100, Andreas Tille wrote:
name = "<some parameter of the script>" cont = container.content
for file in cont.objectValues('File'): if name == file.getId(): foundname=name foundfile=file break
if foundfile.hasProperty('dynscript') : return foundname.dynscript
Shouldn't the last line say: return foundfile.dynscript You are checking whether foundfile has the property 'dynscript', but the returning foundscript.dynscript F.
On Wed, 13 Nov 2002, Felix Ulrich-Oltean wrote:
On Wed, Nov 13, 2002 at 03:50:44PM +0100, Andreas Tille wrote:
name = "<some parameter of the script>" cont = container.content
for file in cont.objectValues('File'): if name == file.getId(): foundname=name foundfile=file break
if foundfile.hasProperty('dynscript') : return foundname.dynscript
Shouldn't the last line say:
return foundfile.dynscript No.
You are checking whether foundfile has the property 'dynscript', but the returning foundscript.dynscript Just imagine there would be a
return 'Hello World' The problem is that the error occures in the if condition. Kind regards Andreas.
Andreas Tille writes:
...
if foundfile.hasProperty('dynscript') : return foundname.dynscript
Shouldn't the last line say:
return foundfile.dynscript No.
You are checking whether foundfile has the property 'dynscript', but the returning foundscript.dynscript Just imagine there would be a
return 'Hello World'
The problem is that the error occures in the if condition. This is almost surely not the case:
1. The "if" line cannot raise an "AttributeError 'dynscript'". 2. The "foundname.dynscript" will as a string does not have an Attribute "dynscript". Check again. You will see that the suggestion was right. Dieter
participants (3)
-
Andreas Tille -
Dieter Maurer -
Felix Ulrich-Oltean