The Python Oracle

How do I determine if an object has an attribute in Python?

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC P Beethoven - Piano Sonata No 2 in A

--

Chapters
00:00 Question
00:28 Accepted answer (Score 3236)
01:11 Answer 2 (Score 804)
01:59 Answer 3 (Score 636)
02:19 Answer 4 (Score 54)
03:09 Thank you

--

Full question
https://stackoverflow.com/questions/6108...

Accepted answer links:
[hasattr()]: https://docs.python.org/3/library/functi...
[zweiterlinde's answer]: https://stackoverflow.com/a/610923/11703...

Answer 2 links:
[Jarret Hardie]: https://stackoverflow.com/questions/6108...
[EAFP vs LBYL (was Re: A little disappointed so far)]: http://web.archive.org/web/2007092912242...
[EAFP vs. LBYL @Code Like a Pythonista: Idiomatic Python]: https://web.archive.org/web/201804110114...

Answer 3 links:
[getattr()]: https://docs.python.org/library/function...

Answer 4 links:
http://docs.python.org/library/functions...
http://mail.python.org/pipermail/python-...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #attributes

#avk47