On Mon, Dec 28, 2020 at 11:36:55PM -0800, Christopher Barker wrote:

> Side Question: when should one use __dict__ vs vars() vs getattr() ??? all
> three work in this case, but I'm never quite sure which is prefered, and
> why.

`vars(obj)` is defined as returning `obj.__dict__` so technically it 
probably doesn't matter, but I feel that as a matter of aesthetics and 
future-proofing, we should avoid direct use of dunders whenever 
practical.

Do you prefer to write `mylist.__len__()` over `len(mylist)`? Then you 
will probably prefer `obj.__dict__` over `vars(obj)` too :-)

-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GNYDVF6VSXREPQJMQOG3CQARXAMT6MEQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to