Which more Pythonic - self.__class__ or type(self)?

Weatherby,Gerard gweatherby at uchc.edu
Sat Mar 4 07:32:40 EST 2023


Nope. No consensus.

I’d use self.__class__ . Seems more explicit and direct to me.

From: Python-list <python-list-bounces+gweatherby=uchc.edu at python.org> on behalf of Ian Pilcher <arequipeno at gmail.com>
Date: Thursday, March 2, 2023 at 4:17 PM
To: python-list at python.org <python-list at python.org>
Subject: Which more Pythonic - self.__class__ or type(self)?
*** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

Seems like an FAQ, and I've found a few things on StackOverflow that
discuss the technical differences in edge cases, but I haven't found
anything that talks about which form is considered to be more Pythonic
in those situations where there's no functional difference.

Is there any consensus?

--
========================================================================
Google                                      Where SkyNet meets Idiocracy
========================================================================
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iK8xBvLrRYfAR0KdkDmK-VwyL0ZZUjFJZ9Tj4j-IBz3_B1M0iQFFE3dV-f4bV41DQwnFL_wC2xWRni-0pMUqAw$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iK8xBvLrRYfAR0KdkDmK-VwyL0ZZUjFJZ9Tj4j-IBz3_B1M0iQFFE3dV-f4bV41DQwnFL_wC2xWRni-0pMUqAw$>


More information about the Python-list mailing list