Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Pause for storage relocation.


devel / comp.lang.python / Which more Pythonic - self.__class__ or type(self)?

SubjectAuthor
* Which more Pythonic - self.__class__ or type(self)?Ian Pilcher
+* Re: Which more Pythonic - self.__class__ or type(self)?Greg Ewing
|+- Re: Which more Pythonic - self.__class__ or type(self)?Thomas Passin
|`- RE: Which more Pythonic - self.__class__ or type(self)?<avi.e.gross
`- Re: Which more Pythonic - self.__class__ or type(self)?Stefan Ram

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

<mailman.2133.1677791747.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22149&group=comp.lang.python#22149

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: arequip...@gmail.com (Ian Pilcher)
Newsgroups: comp.lang.python
Subject: Which more Pythonic - self.__class__ or type(self)?
Date: Thu, 2 Mar 2023 14:54:50 -0600
Lines: 11
Message-ID: <mailman.2133.1677791747.20444.python-list@python.org>
References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de /s2gvsgdwhuRJyOvmVqLmgPi2diCBMLXOfEXB04nSLzw==
Return-Path: <arequipeno@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Gyf4eyGF;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: UNSURE 0.277
X-Spam-Level: **
X-Spam-Evidence: '*H*': 0.56; '*S*': 0.12; 'situations': 0.09;
'talks': 0.14; 'cases,': 0.16; 'pythonic': 0.16;
'subject:Pythonic': 0.16; 'message-id:@gmail.com': 0.18; 'to:addr
:python-list': 0.20; "i've": 0.22; 'to:name:python-
list@python.org': 0.24; 'anything': 0.25; 'seems': 0.26; 'header
:User-Agent:1': 0.30; 'received:209.85.214': 0.32; 'but': 0.32;
'there': 0.33; 'received:google.com': 0.34; 'from:addr:gmail.com':
0.35; 'those': 0.36; 'received:209.85': 0.37; 'received:209':
0.39; "there's": 0.61; 'subject:(': 0.64; 'technical': 0.67;
'functional': 0.69; 'subject:skip:s 10': 0.69; 'discuss': 0.78;
'difference.': 0.84; 'skip:= 70': 0.84; 'meets': 0.91;
'subject:type': 0.91; 'subject:more': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=content-transfer-encoding:subject:from:to:content-language
:user-agent:mime-version:date:message-id:from:to:cc:subject:date
:message-id:reply-to;
bh=pBeM8vac6imgzjy6nEQtIjeFKacNKWXGd9FYm8kVkTA=;
b=Gyf4eyGFo1Eck0qkst7LkUPM6cb7Bf3k9O2WhSBiRwuMneTGwUF5EZRXgufJoAmd9e
NYQ79q5k4f8lgiCxdQrxB1JVELWSS2tpF/syw3OuilC0oJrQAkB1BEiBP9bQgwgivfWf
cOG8U8y8arNlAVddPxWl6VW+/6YfBkd+EGnmtB8Tssgeg5vO6mACGZYc4Pi9JQAl2viu
PD+FeuOlooREb1O628sD5n5uLxv5/mOfFe8EudG71iT9OgScm4yVZusBYr5lD6Diw1Vs
KyrDGNAe/+xkbcqMDoYurY0p/iqENGvUvjVXkxeyWb8UeS/hQyQTqPHh3uBoFOQzyITj
5xbg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=content-transfer-encoding:subject:from:to:content-language
:user-agent:mime-version:date:message-id:x-gm-message-state:from:to
:cc:subject:date:message-id:reply-to;
bh=pBeM8vac6imgzjy6nEQtIjeFKacNKWXGd9FYm8kVkTA=;
b=4RkbFzVmO3BJj7eWMPADoxSaQ4/toxEB6mpLAus3Mc6nvv0R3Yz4sMWWPVrat4ls8z
UDWL4R26vAspkD7nRh8ohOKbVVWFvJ96CFMzyYVvK/HUWYiMtketO9KxCg1DhAzu2kse
74AjT0WPJgWbIv4p5pF4sI7mcooPd+VB5y6LTHxuUUFJ678ZqwXgmSFze+6KBr0Eudwq
WCzeKGFgQMqhSSwvDsEeh3llYrTEQ+8agFvVRzfE1Cykj/vDvlibh1WOZGQh7sHHg8u0
YiMgNFk23GT5WxkK3HKp83Xw+XrCQozch3QPOl1foEyjGLKN+h0bg8Ycy4H4qqEWa9YX
8AnQ==
X-Gm-Message-State: AO0yUKXQDXiRzNLVcxoaBmKFr7sccZRUyFYLdQXGTRxnGy0Z0MU92TCf
pmtelCyFMmSTGJ4CfJdBm7s3f7e9ev0=
X-Google-Smtp-Source: AK7set8wCOfdBirj8aAymgtSBfj7KxON+7juKd53N3PFJMEhX5PLYMxIja+VG1U5p1gw7LHi9kGoqA==
X-Received: by 2002:a05:6808:2082:b0:37f:9335:7f96 with SMTP id
s2-20020a056808208200b0037f93357f96mr5845862oiw.0.1677790491457;
Thu, 02 Mar 2023 12:54:51 -0800 (PST)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
X-Mozilla-News-Host: news://news.gmane.io:119
Content-Language: en-US
X-Mailman-Approved-At: Thu, 02 Mar 2023 16:15:46 -0500
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
 by: Ian Pilcher - Thu, 2 Mar 2023 20:54 UTC

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
========================================================================

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

<k6cnncFps7iU1@mid.individual.net>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22152&group=comp.lang.python#22152

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!lilly.ping.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Which more Pythonic - self.__class__ or type(self)?
Date: Fri, 3 Mar 2023 11:53:28 +1300
Lines: 14
Message-ID: <k6cnncFps7iU1@mid.individual.net>
References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
<mailman.2133.1677791747.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 2YtiwJK+g6z9OUAQatMjggiiYt1wQHA3TWOHH22rrYJ7YpMj0h
Cancel-Lock: sha1:KdkBeR8fKXT0sWr+HM9Bd3aQVx4=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.2133.1677791747.20444.python-list@python.org>
 by: Greg Ewing - Thu, 2 Mar 2023 22:53 UTC

On 3/03/23 9:54 am, Ian Pilcher wrote:
> 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.

In such cases I'd probably go for type(x), because it looks less
ugly.

x.__class__ *might* be slightly more efficient, as it avoids a
global lookup and a function call. But as always, measurement
would be required to be sure.

--
Greg

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

<mailman.2138.1677800999.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22156&group=comp.lang.python#22156

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: lis...@tompassin.net (Thomas Passin)
Newsgroups: comp.lang.python
Subject: Re: Which more Pythonic - self.__class__ or type(self)?
Date: Thu, 2 Mar 2023 18:43:08 -0500
Lines: 16
Message-ID: <mailman.2138.1677800999.20444.python-list@python.org>
References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
<mailman.2133.1677791747.20444.python-list@python.org>
<k6cnncFps7iU1@mid.individual.net>
<a496c87c-c2db-ea57-8df3-0e04169ddd3b@tompassin.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de iCpD3obfteA8mFdz3A0WDANU820uUSPCGig1gkefMIAQ==
Return-Path: <list1@tompassin.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=tompassin.net header.i=@tompassin.net header.b=1ie1an0I;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.041
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'looks': 0.02; 'always,':
0.09; 'lookup': 0.09; 'situations': 0.09; 'talks': 0.14; 'greg':
0.16; 'pythonic': 0.16; 'received:10.0.0': 0.16; 'received:64.90':
0.16; 'received:64.90.62': 0.16; 'received:64.90.62.162': 0.16;
'received:dreamhost.com': 0.16; 'subject:Pythonic': 0.16;
'wrote:': 0.16; 'probably': 0.17; 'pm,': 0.19; 'to:addr:python-
list': 0.20; "i'd": 0.24; 'anything': 0.25; 'function': 0.27;
'header:User-Agent:1': 0.30; 'am,': 0.31; 'python-list': 0.32;
'received:10.0': 0.32; 'received:mailchannels.net': 0.32;
'received:relay.mailchannels.net': 0.32; 'but': 0.32; 'mean':
0.34; 'header:In-Reply-To:1': 0.34; 'cases': 0.36; 'those': 0.36;
"there's": 0.61; 'here': 0.62; 'subject:(': 0.64; 'required':
0.65; 'less': 0.65; 'header:Received:6': 0.67; 'received:64':
0.67; 'functional': 0.69; 'subject:skip:s 10': 0.69; 'global':
0.73; 'difference.': 0.84; 'measurement': 0.84; 'sure.': 0.84;
'subject:type': 0.91; 'subject:more': 0.95
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1677800589; a=rsa-sha256;
cv=none;
b=7RGuv/62he1Ng+wdlT5a8Sx4u7BGy4LYjMivx6vp4Mn5XT2X81GAAajJflEMDccOFl0arZ
IAfFNsWLlT1a4OG2WkAkeJrAJJU8u/6nXc4YtHA23khLfqsH2q8F7MUKlcRgC4PALb2ef+
W29BQV9MV4kuwCkC8rSu8a5l2cUHirAVTADyKFtJJiHijM/x+4pfS5cdVax07ehRDBQNnT
nI5JApN1BjD0as0pOTZLJtah9Bjc45Jf/rs+nMglGfJquBst9XYVv7WbjMRU/qWgR+TL6N
wy/zJInvWu2Pw82cd7IJoHbqrUieiBkfkKQeevP88C7wQdDclFtosAe1lOL08A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed;
d=mailchannels.net; s=arc-2022; t=1677800589;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding:
in-reply-to:in-reply-to:references:references:dkim-signature;
bh=cTYakwmv5XpoDy8bZuKU8Nhob1p/Xws1maa6otbVe/8=;
b=rpkz2iNewEgOa6lfTV1FOeLIix5OOzs3Gnuvi2ywvcyjqcG04G+UJbJ5tD/WmIoRJLBfZX
NIRxPsIacigWH4kgoW/vAzzmJQgfydvZpoAgPp4xwcIWCIWpUfUU13D4KQsThCgiT9oDXH
P+J88STsfKw+9HaW0STJBSeucTt1nnW1hQIg/HdMLLeKeMTM4pjtKYHIxiFRwE49xGhP99
s7vG5ohcZWgx5eXT7Zm7yLwlOUfZxIOIHmPZXF2rdjM0slZUFlwq/Avr5c/FSBQNxRWMZD
L5nM3Jwkh4jdzv1yulcLUUQRgm/Bq2oFK6I9JA1wX8DprSY3e30/CC4ZywH3eQ==
ARC-Authentication-Results: i=1; rspamd-69778c65cd-j6wxb;
auth=pass smtp.auth=dreamhost smtp.mailfrom=list1@tompassin.net
X-Sender-Id: dreamhost|x-authsender|tpassin@tompassin.net
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|tpassin@tompassin.net
X-MailChannels-Auth-Id: dreamhost
X-Bubble-Shelf: 38b4ab5a3df0cd86_1677800589697_2271246323
X-MC-Loop-Signature: 1677800589697:1867285038
X-MC-Ingress-Time: 1677800589697
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tompassin.net;
s=dreamhost; t=1677800589;
bh=cTYakwmv5XpoDy8bZuKU8Nhob1p/Xws1maa6otbVe/8=;
h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding;
b=1ie1an0IRwUwot3cy026e8n4D06VxKPUzRfsJx2ccgBukCPoPyfrIrHvi8WYMc1+v
EsNuDoGEEfTPW4x84HcW0WTNW4wOxgIauUmNBQHbpcqG2H7U23hN+H7+7HiiglTGwm
4Viz4kJVFF/XAoxOeDIBzoJLLRTNNH3/Jke2DOoQIgGXqksewfH7hEpvfiOzQpE+Go
NY2KrceKLRkTKna4XUewUwC++3O5BMGq2eJX0Nq70BolRY1O2Jw5AUXOsHTTfdUVQG
aNI79xVv+7f/EFte+Q9S8tF2gSp/mLL9MXGSJ1wiSy+5c8zib8e1WHrR+4Mg0aK1SN
DUXwLR/BjLWWg==
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Content-Language: en-US
In-Reply-To: <k6cnncFps7iU1@mid.individual.net>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <a496c87c-c2db-ea57-8df3-0e04169ddd3b@tompassin.net>
X-Mailman-Original-References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
<mailman.2133.1677791747.20444.python-list@python.org>
<k6cnncFps7iU1@mid.individual.net>
 by: Thomas Passin - Thu, 2 Mar 2023 23:43 UTC

On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote:
> On 3/03/23 9:54 am, Ian Pilcher wrote:
>> 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.
>
> In such cases I'd probably go for type(x), because it looks less
> ugly.
>
> x.__class__ *might* be slightly more efficient, as it avoids a
> global lookup and a function call. But as always, measurement
> would be required to be sure.

Except that we don't know if "efficiency" - whatever that might mean
here - matters at all.

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

<mailman.2139.1677803745.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22158&group=comp.lang.python#22158

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From:
Newsgroups: comp.lang.python
Subject: RE: Which more Pythonic - self.__class__ or type(self)?
Date: Thu, 2 Mar 2023 19:35:41 -0500
Lines: 45
Message-ID: <mailman.2139.1677803745.20444.python-list@python.org>
References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
<mailman.2133.1677791747.20444.python-list@python.org>
<k6cnncFps7iU1@mid.individual.net>
<a496c87c-c2db-ea57-8df3-0e04169ddd3b@tompassin.net>
<005001d94d68$155af3c0$4010db40$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de MvShHRPXqT57n51WYBokKgPWPIfsxtCbEctGyGtvzDFA==
Return-Path: <avi.e.gross@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=NhO68LPL;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.026
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'looks': 0.02; '2023':
0.07; 'always,': 0.09; 'infinite': 0.09; 'lookup': 0.09;
'received:108': 0.09; 'situations': 0.09; 'talks': 0.14;
'url:mailman': 0.15; 'cases,': 0.16; 'extending': 0.16; 'greg':
0.16; 'leverage': 0.16; 'loops': 0.16; 'pythonic': 0.16;
'relatively': 0.16; 'subject:Pythonic': 0.16; 'wrote:': 0.16;
'python': 0.16; 'probably': 0.17; 'message-id:@gmail.com': 0.18;
'pm,': 0.19; 'to:addr:python-list': 0.20; 'code': 0.23; "i'd":
0.24; 'anything': 0.25; 'skip:- 10': 0.25; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25; 'classes': 0.26;
'object': 0.26; 'creating': 0.27; 'leave': 0.27; 'function': 0.27;
'purpose': 0.28; 'am,': 0.31; 'received:209.85.160': 0.31; 'url-
ip:188/8': 0.31; 'think': 0.32; 'python-list': 0.32; 'but': 0.32;
'march': 0.33; 'mean': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'cases':
0.36; 'count': 0.36; 'functions': 0.36; 'those': 0.36; 'special':
0.37; 'received:209.85': 0.37; 'class': 0.37; 'way': 0.38;
'means': 0.38; 'received:209': 0.39; 'single': 0.39; 'methods':
0.39; 'still': 0.40; 'happen': 0.40; "there's": 0.61; 'from:':
0.62; 'to:': 0.62; 'here': 0.62; 'follow': 0.62; 'mainly': 0.64;
're:': 0.64; 'subject:(': 0.64; 'your': 0.64; 'required': 0.65;
'less': 0.65; 'role': 0.68; 'functional': 0.69; 'subject:skip:s
10': 0.69; 'global': 0.73; 'sent:': 0.78; 'difference.': 0.84;
'exceptions': 0.84; 'measurement': 0.84; 'sure.': 0.84; 'want.':
0.84; 'subject:type': 0.91; 'subject:more': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20210112; t=1677803742;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=qphf29meh15q3RiLfOluVX/pCD8kc9dg5oNXC1vmpBE=;
b=NhO68LPL11GYAmTp/PN58tQ+A5DcR91I5DTpf62SoOoyO8PM9+oTFNbiHGG+jShPck
mtX9riTNe5ggeMl/fsjflgPQ8B58ohSAMUE/AEUnHUa8ivgXeKGr4KmsUrNNE5PVjPW1
r3aStmaVchkB5IXXBtYHyxGwVTQU4I/Izy6tSoBZShxx0pT6S6Hp1BkVrOmLgOhVz/bs
OA3iIueAUxSoNRaKtaqUwQvAnH5i0fjxH/SOh3pPC+BDEQL6HuarSMRGI9j24dt+UdaK
/3PkmZHW85etbc+M/B7k6q6PIc1DBf9z5l0l6wvKdVpE7gkkLI71oBco7cSptWVOpzqk
Pc0g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112; t=1677803742;
h=content-language:thread-index:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=qphf29meh15q3RiLfOluVX/pCD8kc9dg5oNXC1vmpBE=;
b=LKgn4mA0IrGOWnkxbUv6FOEwqhT6ZgZdiy1etGkq8ZZdgZMWv2KwkPwhdpQB3PFlCH
WSdvtpGqovSr6zsj4TSK/oVZx1aodWPomFNkiosBcExDV4IJCWRQyvIXWXPzvqjCZibP
y8a788uYf64Jo6AoKalJkU31+XiycV1/n+th4BR99TuuP8AwatWOABDPd3iPRQurMBty
ST8LE1Zq6nAoTV0IySN2KeowyecbAoJViTATNchHczg3OSObNikmTa4O0ytpJqWWVjL2
AO+l7fOjeUhEHYA0J1jHy4SesY6LgUx+ITY7Ep+PXxp6DWOteMdSoAGZqkAYcnQUdXr6
4bNA==
X-Gm-Message-State: AO0yUKVmohCdZ6+6jODnKlyaHYJkLbsKiLavNiFxguB4GW0SXT0agMmO
6CliqiMO1K8AhSUgXMauH+s=
X-Google-Smtp-Source: AK7set+rR7B1zbCFgwDG6mAkCDQxQrHk6KXltFHbDen9fwr0VjUFy29kuerSAVZWgbgGhYdJnT4TAA==
X-Received: by 2002:a05:622a:14c9:b0:3bf:d359:1a1c with SMTP id
u9-20020a05622a14c900b003bfd3591a1cmr276030qtx.13.1677803742452;
Thu, 02 Mar 2023 16:35:42 -0800 (PST)
In-Reply-To: <a496c87c-c2db-ea57-8df3-0e04169ddd3b@tompassin.net>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQIhnTawdMEPaSLCQZ9+zauIBzeR4gI08QqGApZ5P18B7GF85a4h1VjQ
Content-Language: en-us
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <005001d94d68$155af3c0$4010db40$@gmail.com>
X-Mailman-Original-References: <e3fa13c6-83fa-891e-ca6b-d3c80e940c21@gmail.com>
<mailman.2133.1677791747.20444.python-list@python.org>
<k6cnncFps7iU1@mid.individual.net>
<a496c87c-c2db-ea57-8df3-0e04169ddd3b@tompassin.net>
 by: - Fri, 3 Mar 2023 00:35 UTC

My understanding is that python created functions like type() and len() as a
general purpose way to get information and ALSO set up a protocol that
classes can follow by creating dunder methods. I think the most pythonic
things is to avoid directly calling the dunder methods with a few exceptions
that mainly happen when you are building or extending classes. I mean some
dunder methods are then called directly to avoid getting into infinite loops
that would be triggered.

And note in many cases, the protocol is more complex. Is a length built-in?
If not, can the object be iterated and you count the results? Calling the
function len() may get you more info as it can leverage such things. And it
means you can sometimes leave out some methods and your code still works.

Be warned that type() is a very special function in python and when called
with more arguments, does many relatively beautiful but unrelated things. It
has a special role in the class or type hierarchy. But used with a single
argument, it harmlessly return a result you want.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Thomas Passin
Sent: Thursday, March 2, 2023 6:43 PM
To: python-list@python.org
Subject: Re: Which more Pythonic - self.__class__ or type(self)?

On 3/2/2023 5:53 PM, Greg Ewing via Python-list wrote:
> On 3/03/23 9:54 am, Ian Pilcher wrote:
>> 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.
>
> In such cases I'd probably go for type(x), because it looks less
> ugly.
>
> x.__class__ *might* be slightly more efficient, as it avoids a
> global lookup and a function call. But as always, measurement
> would be required to be sure.

Except that we don't know if "efficiency" - whatever that might mean
here - matters at all.

--
https://mail.python.org/mailman/listinfo/python-list

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

<None-20230303153922@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22168&group=comp.lang.python#22168

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Which more Pythonic - self.__class__ or type(self)?
Date: 3 Mar 2023 14:40:11 GMT
Organization: Stefan Ram
Lines: 28
Expires: 1 Jan 2024 11:59:58 GMT
Message-ID: <None-20230303153922@ram.dialup.fu-berlin.de>
References: <mailman.2133.1677791747.20444.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de KPlVtfGtihe8Y5zT2jTTygczNgbEHgHoYUokzHHaq4EYqC
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Fri, 3 Mar 2023 14:40 UTC

Ian Pilcher <arequipeno@gmail.com> writes:
>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.

Here in USENET, we often use short noun phrases as subjects
and write any questions into the body of the message. If we
use questions in the subject, we repeat them in the body.

~~

Some security guidelines recommend never to access attributes of
"None". For example, the World-Wide Web has:

|Attributes of None values should never be accessed.
"RSPEC-2259"

. Followers of this guideline would not use "None.__class__",
but could use "type( None )". Then, for consistency with the
"None" situation, they could prefer "type( None )" even in
other cases.

(But this guidelines does not seem to take into
consideration that in Python "None" has dunder
attributes which can be accessed without problems.)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor