simple python script question
Hi, I have this in a python script to copy/clone a folder. obj=container.template_folders.template_1 pag=context.manage_clone(obj,id) pag.manage_changeProperties(title=title) This works fine but here template_1 is hardcoded. How do I turn the last segment into a variable so I can call this script with a specific folder to clone? thanks, Henny van der Linde
Did you try template = 'template_1' obj = container.template_folders[template] or template = 'template_1' obj = getattr(container.template_folders,template) Troy Henny van der Linde wrote:
Hi,
I have this in a python script to copy/clone a folder.
obj=container.template_folders.template_1 pag=context.manage_clone(obj,id) pag.manage_changeProperties(title=title)
This works fine but here template_1 is hardcoded. How do I turn the last segment into a variable so I can call this script with a specific folder to clone?
thanks,
Henny van der Linde
_______________________________________________ Zope maillist - Zope@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 )
A 23:42 26/05/2003 -0500, vous avez écrit :
Did you try
template = 'template_1' obj = container.template_folders[template]
or
template = 'template_1' obj = getattr(container.template_folders,template)
Troy
Is there a function to do the same with a path ? For example : template = 'template_folder/template_1' xxxfunction(portal, template) Currently I split the template var and make a loop over a getattr call. Is there a better way to do it ? thx Sébastien Georget http://purl.org/NET/Georget/Sebastien
On Tue, 27 May 2003 09:03:35 +0200 GMT (..9:03 where i live(GMT+2) ) Sébastien Georget asked the Zope mailinglist about the following: SG> A 23:42 26/05/2003 -0500, vous avez écrit :
Did you try
template = 'template_1' obj = container.template_folders[template] ...
SG> Is there a function to do the same with a path ? SG> For example : SG> template = 'template_folder/template_1' SG> xxxfunction(portal, template) context.restrictedTraverse('/path/to/object/as/a/string') :) -- Geir Bækholt
Sébastien Georget schrieb:
Is there a function to do the same with a path ? For example : template = 'template_folder/template_1' xxxfunction(portal, te
Have a look at restrictedTraverse: templatePath = 'template_folder/template_1' templateObject = context.restrictedTraverse(templatePath) Cheers, Maik
participants (5)
-
Geir Bækholt -
Henny van der Linde -
Maik Jablonski -
Sébastien Georget -
Troy Farrell