[Zope] Inserting a variable in a context.manage statement in Python

Dan Shafer pydan@danshafer.com
Tue, 23 Apr 2002 09:59:38 -0700


Fantastic! This was exactly the missing key, Tim. Thanks very much! I think 
this was the last major technical gap I had before I can complete this 
application.

This list is wonderful. You are most helpful. One more reason to keep using 
Zope and Python.

At 02:33 PM 4/23/2002 +0100, tim wrote:
> > c = REQUEST.get('clearing_id','')
> > context.manage_addFolder(c) # this works
> > # Now what I want to do is add a document to the folder
> > # If I include a hard-coded value for the folder name I just created as a
> > test, it works
> > # But this doesn't:
> > context.c.manage_addDocument('NewDoc')
>
>I think you should be able to do either of (both untested):
>
>getattr(context, c).manage_addDocument('NewDoc')
>context[c].manage_addDocument('NewDoc')
>
>As far as I understand, your version doesn't work because you are telling
>python/zope to look for the c string object that is an attribute of context,
>instead of telling it to get hold of the attribute of context that is called
>whatever str(c) returns.
>
>hth
>
>tim