[Zope] getitem from python

hans hans@beehive.de
Wed, 29 May 2002 12:45:58 +0100


Roman Bogoyev wrote:

> Please excuse this newbie question:
>
> How do I refer to an object from a variable in a python script?
>
> eg:
>
> Have a document named 'mydoc' in the current folder where this
> script lives:
>
> print context.mydoc.title_or_id()
>
> works but I want
>
> fred = 'mydoc'
> print context.fred.title_or_id()
>
> which obviously doesn't. So I need to
> turn the string 'mydoc' into an object
> reference.  Something like the dtml 'getitem'??
> --

you cant get an object unless you already have an object,
in this case context.
how abt
fred = getattr(context, 'mydoc')?

also check absolute_url, restrictedTraverse in Zope Book Appendix API
--
-------------------------------------------------------------
Who's got only a hammer sees the world as a nail
hans augustin  (software developer)           hans@beehive.de
beehive elektronische medien GmbH       http://www.beehive.de
phone: +49 30 847-82 0                  fax: +49 30 847-82 299