getitem from python
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'?? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Roman Bogoyev, Computer Systems Manager, email: roman@maths.uwa.edu.au UWA Maths, 35 Stirling Hwy, Crawley, phone: +61 8 9380 3379 Western Australia 6009 fax: +61 8 9380 1028
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
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
participants (3)
-
hans -
Maik Jablonski -
Roman Bogoyev