Changing context in Python Script
Given the need for a Python script to: a. create a new folder whose name is stored in a variable called folderName b. within that folder create a new doc whose name is stored in a variable called docName what is the appropriate syntax? I can see that I need to change the context but I can't find anything on how to do that. Thanks.
On Thu, 2002-05-16 at 09:33, Dan Shafer wrote:
Given the need for a Python script to:
a. create a new folder whose name is stored in a variable called folderName b. within that folder create a new doc whose name is stored in a variable called docName
what is the appropriate syntax? I can see that I need to change the context but I can't find anything on how to do that.
hi, use something like this: # create Folder in context context.manage_addFolder(folderName) folderObj=getattr(context,folderName) # create DTMLDoc in new folder folderObj.manage_addDTMLDocument(docName) docObj=getattr(folderObj,docName) ... from here you can manipulate docObj ... regards, maik -- maik jablonski http://www.sachunterricht-online.de universitaet bielefeld http://www.zfl.uni-bielefeld.de zentrum fuer lehrerbildung tlph://+49.(0).521.106.4234
Thanks, Maik! This was the missing piece: folderObj=getattr(context,folderName) I guess you only learn this stuff by asking. I sure couldn't find it on my own in the docs! It's exactly what I need. At 10:00 AM 5/16/2002 +0200, Maik Jablonski wrote:
On Thu, 2002-05-16 at 09:33, Dan Shafer wrote:
Given the need for a Python script to:
a. create a new folder whose name is stored in a variable called folderName b. within that folder create a new doc whose name is stored in a variable called docName
what is the appropriate syntax? I can see that I need to change the context but I can't find anything on how to do that.
hi,
use something like this:
# create Folder in context
context.manage_addFolder(folderName) folderObj=getattr(context,folderName)
# create DTMLDoc in new folder
folderObj.manage_addDTMLDocument(docName) docObj=getattr(folderObj,docName)
... from here you can manipulate docObj ...
regards, maik -- maik jablonski http://www.sachunterricht-online.de universitaet bielefeld http://www.zfl.uni-bielefeld.de zentrum fuer lehrerbildung tlph://+49.(0).521.106.4234
On Thursday 16 May 2002 03:33 pm, Dan Shafer wrote:
Given the need for a Python script to:
a. create a new folder whose name is stored in a variable called folderName b. within that folder create a new doc whose name is stored in a variable called docName
what is the appropriate syntax? I can see that I need to change the context but I can't find anything on how to do that.
Thanks.
#parameter list folderName docname o=context o.manage_addProduct['OFSP'].manage_addFolder(folderName) folder = getattr(context, foldername) folder.manage_addProduct['OFSP'].manage_addDTMLDocument(docName) oughta work
_______________________________________________ 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 )
-- http://www.kedai.com.my/ http://www.kedai.com.my/eZine http://www.zope.org/Members/kedai http://www.my-zope.org As you woke this morning, and open up your eyes... did you notice the tear stains lining your face were mine.
participants (3)
-
Bakhtiar A Hamid -
Dan Shafer -
Maik Jablonski