Access "slot" field dynamically?
Robert Oschler
no_replies at fake_email_address.invalid
Tue Jun 10 09:49:12 EDT 2003
I want to pass a list of field names (slot names?) that represent the slots
in a class instance, and have a method do something with them. For example
class HasSlots(object):
__slots__ = 'fldone', 'fldtwo', 'fldthree'
def __init__(self):
self.fldone = ""
self.fldtwo = ""
self.fldthree = ""
# END: __init__
# END: class HasSlots()
def printSomeFields(instance_of_hasslot, fldlist):
for fl in fldlist:
# Here is where I don't know the syntax for
# accessing a field of instance_of_hasslot, by
# using a Python string that contains the
# desired field name.
# END: printSomeFields
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
doesn't work.
thx
--
Robert Oschler,
Android Technologies, Inc.
http://www.androidtechnologies.com
- The home of Off-Book! (tm)
The scene memorization tool for Actors and Actresses!
More information about the Python-list
mailing list