[Zope] getitem from python

Maik Jablonski maik.jablonski@uni-bielefeld.de
29 May 2002 12:57:34 +0200


On Wed, 2002-05-29 at 12:24, 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'?? 

print getattr(context,fred).title_or_id()

keep zoped -mj

-- 
maik jablonski                    http://www.sachunterricht-online.de
 universitaet bielefeld          http://www.zfl.uni-bielefeld.de
  zentrum fuer lehrerbildung    tlph://+49.(0).521.106.4234