osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dunder variables


Frank Millman wrote:

> Hi all
> 
> I have read that one should not call dunder methods in application code.
> 
> Does the same apply to dunder variables? I am thinking of the instance
> attribute __dict__, which allows access to the contents of the instance.
> 
> I only want to read from __dict__, not update it. Is this frowned upon?

Why would you care whether it is "frowned upon" if it's the best way to 
achieve something useful?

So the real question is /what/ you are trying to do and what your options 
are.

PS: vars(a) is the non-dunder equivalent of a.__dict__. Both have the same 
limitations, like failing with __slots__ and not seeing properties and class 
attributes.