On Jul 8, 2:31 pm, "OKB (not okblacke)"
<[EMAIL PROTECTED]> wrote:
> mshiltonj wrote:
> > In python, I'm doing something like this:
>
> > def three_fields(self, field1, field2, field3):
> > for field in (field1, field2, field3):
> > value = eval('self.' + field) # this is the one
mshiltonj wrote:
> In python, I'm doing something like this:
>
> def three_fields(self, field1, field2, field3):
> for field in (field1, field2, field3):
> value = eval('self.' + field) # this is the one I'm
> interested in
> [...]
>
> This seems to do what I expect
On Sun, 08 Jul 2007 18:21:41 -, mshiltonj <[EMAIL PROTECTED]> wrote:
>I'm trying to find the preferred python idiom for access arbitrary
>fields of objects at run time.
>
It's not an idiom, it's a built-in function: getattr.
Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to find the preferred python idiom for access arbitrary
fields of objects at run time.
For example, say I have an object the business code will do
*something* with three arbitrary fields at a given time, but I don't
know what the three fields are at run time. In perl, I'd do something