Access "slot" field dynamically?

Robert Oschler no_replies at fake_email_address.invalid
Tue Jun 10 19:03:01 CEST 2003


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.


Robert Oschler,
Android Technologies, Inc.
- The home of Off-Book! (tm)
The scene memorization tool for Actors and Actresses!

"Steven Taschuk" <staschuk at> wrote in message
news:mailman.1055258590.26664.python-list at
> 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
> "Telekinesis would be worth patenting."  -- James Gleick

More information about the Python-list mailing list