[Zope] selecting tinytableplus to update by parameter

J Cameron Cooper jccooper at jcameroncooper.com
Fri Jan 23 15:37:47 EST 2004


John wrote:

> I'm new to zope/python and hope this is fairly easy - I want to update
> a TinyTablePlus table from a script.  So the following will do what I
> want on the table 'igrid'.
>
> context.igrid.setRow(number=number,score=newscore)
>
> But how can I do this on different tables where the table is passed to
> the script as a parameter - instead of igrid  I want to include the
> value of the parameter.

There are many ways of getting an object from another object based on 
name. You can see zopelabs.com or the Zope book for some examples. One 
of the most common (with your context) is::

somevariable = "igrid"
obj = context[somevariable]
obj.setRow(...)

You can imagine how to collapse the last two lines. (I didn't do it for 
illustrative purposes.) Keep in mind that if 'context' doesn't contain 
the thing named by 'somevariable' then you will get a KeyError. You may 
either catch this, check first (has _key), or use another method 
(getattr, restrictedTraverse).

http://www.python.org/doc/current/lib/built-in-funcs.html
http://www.python.org/doc/current/lib/typesmapping.html

Also, follow this thread:
http://mail.zope.org/pipermail/zope/2003-September/141117.html

          --jcc

-- 
"Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design."
(http://www.devx.com/java/editorial/15511)





More information about the Zope mailing list