Re: In search of python idiom for accessing arbitrary fields at run time

2007-07-08 Thread mshiltonj
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

Re: In search of python idiom for accessing arbitrary fields at run time

2007-07-08 Thread OKB (not okblacke)
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

Re: In search of python idiom for accessing arbitrary fields at run time

2007-07-08 Thread Jean-Paul Calderone
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

In search of python idiom for accessing arbitrary fields at run time

2007-07-08 Thread mshiltonj
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