getting all user defined attributes of a class
george.sakkis at gmail.com
Thu Feb 7 20:49:16 CET 2008
On Feb 7, 1:42 pm, Amit Gupta <emaila... at gmail.com> wrote:
> Thanks. What I found is: If I call iterate over the __dict__ of the
> instance of the class, I only get user-atttributes and not built-in
> attributes. I have an instance of that class, anyway, so this will do.
> However, I wonder if I am getting just lucky and this might change in
> future. In that regard the solution provides by all posters above
> might well be more robust.
Instances and classes have separate namespaces:
x = 1
self.y = 2
<dictproxy object at 0xb7beab9c>
('__dict__', <attribute '__dict__' of 'X' objects>),
('__weakref__', <attribute '__weakref__' of 'X' objects>),
('__init__', <function __init__ at 0xb7b5a454>)]
And neither of those includes attributes defined in superclasses,
classes with __slots__, pseudo-attributes through __getattr__ and
possibly more I've missed.
More information about the Python-list