Access "slot" field dynamically?

Duncan Booth duncan at
Tue Jun 10 16:06:38 CEST 2003

"Robert Oschler" <no_replies at fake_email_address.invalid> wrote in 
news:sllFa.660$Hw.844355 at

> In the block belonging to "printSomeFields()", how do I access the field
> (slot) by grabbing the field name from the fldlist list of strings?
>     print instance_of_hasslot.fl

Use the 'getattr' function. e.g.

print getattr(instance_of_hasslot, fl)

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list