Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Try to get all of your posthumous medals in advance.


comp / comp.lang.python / Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)

SubjectAuthor
* Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)Lawrence D'Oliveiro
+* Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)Paul Rubin
|`- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)Lawrence D'Oliveiro
+- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)Keith Thompson
`- Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)Lawrence D'Oliveiro

1
Subject: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sun, 23 Jun 2024 01:17 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Checking That Two Args Are Of Same Type (Posting On Python-List
Prohibited)
Date: Sun, 23 Jun 2024 01:17:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <v57t3f$tpf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Jun 2024 03:17:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="be24819e5877b282c066214411113658";
logging-data="30511"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fuyg17HXDKMK9Gu4DQd7d"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:iWHC3QZ2JbLFDy715wW0lsPu3o8=
View all headers

Consider a function taking two args “a” and “b”, which can be of str,
bytes or bytearray type, just so long as both are of the same type.
One easy way to test this is

if sum(isinstance(a, t) and isinstance(b, t) for t in (str, bytes, bytearray)) != 1 :
raise TypeError("args must both be str or bytes")
#end if

Actually, both “and’ and “or” will work.

Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
From: Keith Thompson
Newsgroups: comp.lang.python
Organization: None to speak of
Date: Sun, 23 Jun 2024 05:56 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.lang.python
Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
Date: Sat, 22 Jun 2024 22:56:32 -0700
Organization: None to speak of
Lines: 9
Message-ID: <87v820td67.fsf@nosuchdomain.example.com>
References: <v57t3f$tpf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 23 Jun 2024 07:56:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4fd171a301c9caad40652f36602e6fff";
logging-data="238085"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IVIawI36guNBTPfKDSEVL"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:IDCGz4Hc0bPxLQt4cd1jvXwVf6Q=
sha1:tg2Uv6ZAEFwCpfQTtlfBOICzowE=
View all headers

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
[snip]

Just curious, why do you add "Posting On Python-List Prohibited" to your
subject lines?

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
From: Paul Rubin
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sun, 23 Jun 2024 07:00 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
Date: Sun, 23 Jun 2024 00:00:29 -0700
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <871q4ota7m.fsf@nightsong.com>
References: <v57t3f$tpf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Jun 2024 09:00:30 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="13def561b04cf0e136ded44458e43f56";
logging-data="256619"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+isjr0xeddZ7WDK3gm5dQC"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:LTqrAl3u06vNmBlj0xEsS9bLM0E=
sha1:N3OlNusLcdGeH4wrUPAY7Es9yLw=
View all headers

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> Consider a function taking two args “a” and “b”, which can be of str,
> bytes or bytearray type, just so long as both are of the same type.
> One easy way to test this is

if type(a)==type(b) and type(a) in (str, bytes, bytearray): ...

Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sun, 23 Jun 2024 07:13 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List
Prohibited)
Date: Sun, 23 Jun 2024 07:13:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v58hum$7vgu$1@dont-email.me>
References: <v57t3f$tpf$1@dont-email.me> <871q4ota7m.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 23 Jun 2024 09:13:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="be24819e5877b282c066214411113658";
logging-data="261662"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9ZLgixZWHocTrCvkoqfVG"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:jBxRbZL1RdRM1e+0l7mespM32Q4=
View all headers

On Sun, 23 Jun 2024 00:00:29 -0700, Paul Rubin wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> Consider a function taking two args “a” and “b”, which can be of str,
>> bytes or bytearray type, just so long as both are of the same type.
>> One easy way to test this is
>
> if type(a)==type(b) and type(a) in (str, bytes, bytearray): ...

Better to use isinstance instead of direct type comparison.

Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sun, 23 Jun 2024 22:55 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Checking That Two Args Are Of Same Type (Posting On Python-List
Prohibited)
Date: Sun, 23 Jun 2024 22:55:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <v5a951$i4c8$1@dont-email.me>
References: <v57t3f$tpf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 24 Jun 2024 00:55:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3048fea01d51f9337586ac8e02824e6c";
logging-data="594312"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZYCpKk1KIw+fZox4BHRSR"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:as8ddMK/PB/vguvc/zYLd5oWzyQ=
View all headers

On Sun, 23 Jun 2024 01:17:35 -0000 (UTC), Lawrence D'Oliveiro wrote:

> Actually, both “and’ and “or” will work.

No it won’t. It’ll fail in the case where one or the other arg is of an
entirely different type.

1

rocksolid light 0.9.8
clearnet tor