Access "slot" field dynamically?
Robert Oschler
no_replies at fake_email_address.invalid
Tue Jun 10 13:03:01 EDT 2003
Steven
I've read the the same comment but I like the bug-prevention aspects of it
too much to not use it and it doesn't seem to harm anything.
thx
--
Robert Oschler,
Android Technologies, Inc.
http://www.androidtechnologies.com
- The home of Off-Book! (tm)
The scene memorization tool for Actors and Actresses!
"Steven Taschuk" <staschuk at telusplanet.net> wrote in message
news:mailman.1055258590.26664.python-list at python.org...
> Quoth Robert Oschler:
> [...]
> > 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
>
> What you need is
>
> print getattr(instance_of_hasslot, fl)
>
> Btw, I don't think __slots__ is something you should use for your
> run-of-the-mill classes. It's intended for memory optimization
> for classes with lots and lots and lots of instances, afaik
> (contrary to some of the documentation, which suggests a
> bug-prevention role).
>
> --
> Steven Taschuk staschuk at telusplanet.net
> "Telekinesis would be worth patenting." -- James Gleick
>
More information about the Python-list
mailing list