Emulating a = x.y and x.y = a, when 'y' is a string

Michael Hudson mwh at python.net
Thu Oct 17 09:27:22 EDT 2002


Bruce Dawson <bruce_deletethis_dawson at cygnus-software.com> writes:

> I want to do dynamic access to member variables in Python - reading
> from and writing to object member variables based on a member name
> stored in a string. If the member is stored in __dict__ it is easy
> enough, but what if it is emulated with __getattr__, or a property, or
> __getattribute__?

I think you're looking for the builtin functions getattr and setattr.

Cheers,
M.

-- 
  same software, different verbosity settings (this one goes to
  eleven)                             -- the effbot on the martellibot



More information about the Python-list mailing list