Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Factorials were someone's attempt to make math LOOK exciting.


devel / comp.lang.python / RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

SubjectAuthor
* builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
+* Re: builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
|`* Re: builtins.TypeError: catching classes that do not inherit fromChris Angelico
| `* Re: builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
|  `- Re: builtins.TypeError: catching classes that do not inherit fromChris Angelico
+* Re: builtins.TypeError: catching classes that do not inherit fromChris Angelico
|`* Re: builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
| `* Re: builtins.TypeError: catching classes that do not inherit fromChris Angelico
|  +* Re: builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
|  |+* Re: builtins.TypeError: catching classes that do not inherit fromMRAB
|  ||`* Re: builtins.TypeError: catching classes that do not inherit fromhongy...@gmail.com
|  || +- Re: builtins.TypeError: catching classes that do not inherit fromKarsten Hilbert
|  || `- RE: builtins.TypeError: catching classes that do not inherit fromAvi Gross
|  |`- RE: builtins.TypeError: catching classes that do not inherit fromAvi Gross
|  `- Re: builtins.TypeError: catching classes that do not inherit from BaseException Paul Rubin
`- Re: builtins.TypeError: catching classes that do not inherit fromMarco Sulla

1
builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:622a:1652:: with SMTP id y18mr26640519qtj.63.1640869465227;
Thu, 30 Dec 2021 05:04:25 -0800 (PST)
X-Received: by 2002:ac8:5792:: with SMTP id v18mr27323578qta.610.1640869465061;
Thu, 30 Dec 2021 05:04:25 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 05:04:24 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
Subject: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 13:04:25 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 96
 by: hongy...@gmail.com - Thu, 30 Dec 2021 13:04 UTC

I try to compute the factorial of a large number with tail-recursion optimization decorator in Python3. The following code snippet is converted from the code snippet given here [1] by the following steps:

$ pyenv shell datasci
$ python --version
Python 3.9.1
$ pip install 2to3
$ 2to3 -w this-script.py

```
# This program shows off a python decorator(
# which implements tail call optimization. It
# does this by throwing an exception if it is
# its own grandparent, and catching such
# exceptions to recall the stack.

import sys

class TailRecurseException:
def __init__(self, args, kwargs):
self.args = args
self.kwargs = kwargs

def tail_call_optimized(g):
"""
This function decorates a function with tail call
optimization. It does this by throwing an exception
if it is its own grandparent, and catching such
exceptions to fake the tail call optimization.

This function fails if the decorated
function recurses in a non-tail context.
"""
def func(*args, **kwargs):
f = sys._getframe()
if f.f_back and f.f_back.f_back \
and f.f_back.f_back.f_code == f.f_code:
raise TailRecurseException(args, kwargs)
else:
while 1:
try:
return g(*args, **kwargs)
except TailRecurseException as e:
args = e.args
kwargs = e.kwargs
func.__doc__ = g.__doc__
return func

@tail_call_optimized
def factorial(n, acc=1):
"calculate a factorial"
if n == 0:
return acc
return factorial(n-1, n*acc)

print(factorial(10000))
# prints a big, big number,
# but doesn't hit the recursion limit.

@tail_call_optimized
def fib(i, current = 0, next = 1):
if i == 0:
return current
else:
return fib(i - 1, next, current + next)

print(fib(10000))
# also prints a big number,
# but doesn't hit the recursion limit.
```
However, when I try to test the above script, the following error will be triggered:
```
$ python this-script.py
Traceback (most recent call last):
File "/home/werner/this-script.py", line 32, in func
return g(*args, **kwargs)
File "/home/werner/this-script.py", line 44, in factorial
return factorial(n-1, n*acc)
File "/home/werner/this-script.py", line 28, in func
raise TailRecurseException(args, kwargs)
TypeError: exceptions must derive from BaseException

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/werner/this-script.py", line 46, in <module>
print(factorial(10000))
File "/home/werner/this-script.py", line 33, in func
except TailRecurseException as e:
TypeError: catching classes that do not inherit from BaseException is not allowed
```

Any hints for fixing this problem will be highly appreciated.

[1] https://stackoverflow.com/q/27417874

Regards,
HZ

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:622a:4ce:: with SMTP id q14mr27070035qtx.627.1640870057855;
Thu, 30 Dec 2021 05:14:17 -0800 (PST)
X-Received: by 2002:a05:620a:244a:: with SMTP id h10mr21267994qkn.173.1640870057722;
Thu, 30 Dec 2021 05:14:17 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 05:14:17 -0800 (PST)
In-Reply-To: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 13:14:17 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 98
 by: hongy...@gmail.com - Thu, 30 Dec 2021 13:14 UTC

On Thursday, December 30, 2021 at 9:04:36 PM UTC+8, hongy...@gmail.com wrote:
> I try to compute the factorial of a large number with tail-recursion optimization decorator in Python3. The following code snippet is converted from the code snippet given here [1] by the following steps:
>
> $ pyenv shell datasci
> $ python --version
> Python 3.9.1
> $ pip install 2to3
> $ 2to3 -w this-script.py
>
> ```
> # This program shows off a python decorator(
> # which implements tail call optimization. It
> # does this by throwing an exception if it is
> # its own grandparent, and catching such
> # exceptions to recall the stack.
>
> import sys
>
> class TailRecurseException:
> def __init__(self, args, kwargs):
> self.args = args
> self.kwargs = kwargs
>
> def tail_call_optimized(g):
> """
> This function decorates a function with tail call
> optimization. It does this by throwing an exception
> if it is its own grandparent, and catching such
> exceptions to fake the tail call optimization.
>
> This function fails if the decorated
> function recurses in a non-tail context.
> """
> def func(*args, **kwargs):
> f = sys._getframe()
> if f.f_back and f.f_back.f_back \
> and f.f_back.f_back.f_code == f.f_code:
> raise TailRecurseException(args, kwargs)
> else:
> while 1:
> try:
> return g(*args, **kwargs)
> except TailRecurseException as e:
> args = e.args
> kwargs = e.kwargs
> func.__doc__ = g.__doc__
> return func
>
> @tail_call_optimized
> def factorial(n, acc=1):
> "calculate a factorial"
> if n == 0:
> return acc
> return factorial(n-1, n*acc)
>
> print(factorial(10000))
> # prints a big, big number,
> # but doesn't hit the recursion limit.
>
> @tail_call_optimized
> def fib(i, current = 0, next = 1):
> if i == 0:
> return current
> else:
> return fib(i - 1, next, current + next)
>
> print(fib(10000))
> # also prints a big number,
> # but doesn't hit the recursion limit.
> ```
> However, when I try to test the above script, the following error will be triggered:
> ```
> $ python this-script.py
> Traceback (most recent call last):
> File "/home/werner/this-script.py", line 32, in func
> return g(*args, **kwargs)
> File "/home/werner/this-script.py", line 44, in factorial
> return factorial(n-1, n*acc)
> File "/home/werner/this-script.py", line 28, in func
> raise TailRecurseException(args, kwargs)
> TypeError: exceptions must derive from BaseException
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "/home/werner/this-script.py", line 46, in <module>
> print(factorial(10000))
> File "/home/werner/this-script.py", line 33, in func
> except TailRecurseException as e:
> TypeError: catching classes that do not inherit from BaseException is not allowed
> ```
>
> Any hints for fixing this problem will be highly appreciated.

See here [1] for the related discussion.

[1] https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800

HZ

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 02:23:05 +1100
Lines: 36
Message-ID: <mailman.70.1640877797.3079.python-list@python.org>
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de xXN7DumJ0/LI2F2OoI/wtAW4Iuki1Ah6G8VneXpOK1Zg==
Return-Path: <rosuav@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=AB6Qg81H;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.008
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'looks': 0.02; 'def': 0.04;
'pip': 0.04; '31,': 0.05; 'compute': 0.09; 'subject:not': 0.09;
'import': 0.15; '(also,': 0.16; '3.9.1': 0.16; 'algorithms': 0.16;
'chrisa': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'implements': 0.16; 'python3.': 0.16; 'recall':
0.16; 'recursion': 0.16; 'stack.': 0.16; 'wrote:': 0.16; 'python':
0.16; 'to:addr:python-list': 0.20; 'exception': 0.22; 'fri,':
0.22; 'skip:_ 10': 0.22; 'install': 0.23; 'code': 0.23; "isn't":
0.27; 'dec': 0.31; 'program': 0.31; "wouldn't": 0.32; 'message-
id:@mail.gmail.com': 0.32; 'but': 0.32; 'there': 0.33; 'same':
0.34; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'handling': 0.35; 'subject:that': 0.35; 'yes,': 0.35; 'following':
0.35; 'from:addr:gmail.com': 0.35; 'subject:from': 0.37; 'really':
0.37; "it's": 0.37; 'received:209.85': 0.37; 'class': 0.37; 'way':
0.38; 'received:209': 0.39; 'try': 0.40; 'skip:o 10': 0.61;
'here': 0.62; 'email addr:gmail.com': 0.63; 'skip:b 10': 0.63;
'benefit': 0.65; 'skip:t 20': 0.66; 'shows': 0.67; '[1]': 0.67;
'2021': 0.71; '2:00': 0.84; 'catching': 0.84; 'converted': 0.84;
'exceptions': 0.84; 'subject: \n ': 0.84; 'optimization': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=f5cPLGhWMPm6W6pnN1nzWqsIjxo7vqnLvPHol++Nesk=;
b=AB6Qg81HWI+fN1BXpyz5ZkxdJeRLYNw+KT5/ou/FCv4DeTJmiKizWQOwCXm9pEVIU3
xZalD3ewyABC99PdEJmhfrggmIP8u8WYp07lfA9gU4yFzzZMNS9Lx33p3OLPoZJL7EUH
8zRXoEz4GbBL77glECcJ7wRLVibYpJYcDITJmzek9JJyBcbVyYlRRJWnwhj2mMl0FgOq
Gw+zhJ8AFn8niCPHgU5MHSV49d5yPxBeiodk6ijB8dTjHyWR+iM+G5XOM/umEb9fJkbY
Vw4gws4MbLBXWmCtkH/vW+go24g0pwbptWJd4FcmUqYzbC6x6o8rKjVhs13WikGPICjz
3aNQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=f5cPLGhWMPm6W6pnN1nzWqsIjxo7vqnLvPHol++Nesk=;
b=kNa1yDT5VSLkwhyBVpfDUKlEEBW5B/pEy5yBdPnlUAeHYd0wf1XIWL26biMa2vTc/w
73GmzbBULlgMfP+Pe4n1rD/ZTQ58N9CEOH1wQSdKPjTm0SZ4SYHX3b/X/lVC9tk9gJag
HrOfYQa7FxvRGjJ7T9/NhhC1HGwMRwL+jBdhXZPlkyXq8MI5Y2q1FuBAp6n6Ln7turXH
enTgdr85Z4PG3Zv2T3MovYCFKC0m0O4LbJ8UaqT1Sw/lNw6nnPtgy0skq/OVTUf7g20m
INjP+UQVAj3V0XzObeeNdpRfAbbEaMn98sFspIc3ytX7pNCYXPbADnRpxsSq7EsQ3FSa
Kfmw==
X-Gm-Message-State: AOAM531z7dV3uP02XuFHzVQyO5kx6yfh14INAI2WCq6VuNq8K1We6r4o
yKxXkvnl2xRcL+z38W1DiM2pT/6DCvRSHSg1G8gi0Qao
X-Google-Smtp-Source: ABdhPJwaA2+4k/u6gH9KGme9WBJEDeZgNajluuzKbCDX1Wv2EcuMKWeVaZbytwrOLpb+JeLVxVxf958wAZTufWZ2GtE=
X-Received: by 2002:a5d:4486:: with SMTP id j6mr24435343wrq.160.1640877796243;
Thu, 30 Dec 2021 07:23:16 -0800 (PST)
In-Reply-To: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
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: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
X-Mailman-Original-References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
 by: Chris Angelico - Thu, 30 Dec 2021 15:23 UTC

On Fri, Dec 31, 2021 at 2:00 AM hongy...@gmail.com
<hongyi.zhao@gmail.com> wrote:
>
> I try to compute the factorial of a large number with tail-recursion optimization decorator in Python3. The following code snippet is converted from the code snippet given here [1] by the following steps:
>
> $ pyenv shell datasci
> $ python --version
> Python 3.9.1
> $ pip install 2to3
> $ 2to3 -w this-script.py
>
> ```
> # This program shows off a python decorator(
> # which implements tail call optimization. It
> # does this by throwing an exception if it is
> # its own grandparent, and catching such
> # exceptions to recall the stack.
>
> import sys
>
> class TailRecurseException:
> def __init__(self, args, kwargs):
> self.args = args
> self.kwargs = kwargs
>

If it's an exception, it needs to subclass Exception or BaseException.

(Also, is this REALLY an optimization? Exception handling isn't the
fastest. Yes, it avoids some measure of recursion depth, but it looks
like a pretty inefficient way to do things. Python is not Lisp, and
there are very very few algorithms that actually benefit from tail
call optimization that wouldn't benefit far more from other ways of
doing the same thing.)

ChrisA

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 02:23:49 +1100
Lines: 10
Message-ID: <mailman.71.1640877841.3079.python-list@python.org>
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
<CAPTjJmpXZ9FbymOHUvXU0JaxETjCq0TXZCLHffcy9iJpzpOtaA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de L+JX2PKqBPDvppDb6yC5WQzpRAUZFtj0dE3JxeYKd0Ug==
Return-Path: <rosuav@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=YDSncJr6;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.019
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '31,': 0.05; 'subject:not':
0.09; 'url-ip:184.105.176.44/32': 0.09; 'url-ip:184.105.176/24':
0.09; 'url-ip:184.105/16': 0.09; 'url:discuss': 0.09; 'chrisa':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'message?': 0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20;
'fri,': 0.22; 'error': 0.29; 'dec': 0.31; 'message-
id:@mail.gmail.com': 0.32; 'same': 0.34; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'subject:that': 0.35;
'from:addr:gmail.com': 0.35; 'people': 0.36; 'subject:from': 0.37;
'received:209.85': 0.37; 'received:209': 0.39; 'two': 0.39;
'tell': 0.60; 'here': 0.62; 'email addr:gmail.com': 0.63; '[1]':
0.67; '2021': 0.71; 'url:t': 0.73; 'subject: \n ': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=zU3n3eIJX024nkEH1UBLIG7UIS5aKHI+okRUlmM81eE=;
b=YDSncJr6WBfrbHXnUDz9U/23Doq0eoXyD4X0d6Zszg6qa/Bf99LkKS8U5gkNKVzmv4
xX4lswBAZIYo5h53p2ShN8BOghPMEEbP6rQF3mJEAAJw+q6KUEpu3uB4EZZKN58Jxxx6
sIc8t3Q8Pi2uuxlnMYN7sMkUvnFn9WhrcWTWToZ7rP9kyrvZv+9p76gL1at7d5620YCP
9TZ1nqi0OUbiwJXbaLLtfSfiD7vmBhD+/RXZJ9YVwA90uZhM2ChdDVTt82YfRbMejk79
t1mwc6nRAKFUUU9M4xfaD9+mFWbEVkXtvVgkC46+Pb+9WIycxBTdDhyIKMk7GDmdGLeh
obpQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=zU3n3eIJX024nkEH1UBLIG7UIS5aKHI+okRUlmM81eE=;
b=r3L8ufBaPSzxIRdFbs+cNVdod2hZklAcc0agNgkNywCaWcLLCqD/Bv4xK4Dq9W8GpK
8/AJOx+XHPd3U23oEex5m1kktSKSyWsNAPYHXGkszQ0jreniYLk7fAOAQO/Y+DqCK6Ty
OUsxa1/V6uo/3jgSbGSBHST3ZjxgzsAFMbjXlx9MkjTFDc9s32rO3o2pmbxnrnRuOS2f
c9Il965JfCBAeXnnN+bgTYLBLYkq8s0YGH9orc6MGuE5/AWF5ZAmEoBE7BbmL/6GEm88
8makDleGD1tVuC4Dt8Z0DZ9hZwPrvA5ccGhKjSF7W0R2md2MzWFV7IK/G51VTsZBI/EW
3enA==
X-Gm-Message-State: AOAM530fLSsADqG+DkZyhunDiZ7KPSDRAZRM22v/N0KBhWpQ/0qziRTP
GFAZafCmt4yYQQgxlWvm6T6AYvCil5OGkaNKPabjLPsp
X-Google-Smtp-Source: ABdhPJywAIZCV0HFVe/xTgLrOX7vo1Nfkr2Nk3BAHKgfBbuUAHEm89+4pTDcUy/Dj/GPwr93msLsP/cPFvLCvYIFaus=
X-Received: by 2002:a05:6000:156c:: with SMTP id
12mr24934877wrz.104.1640877840651;
Thu, 30 Dec 2021 07:24:00 -0800 (PST)
In-Reply-To: <c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
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: <CAPTjJmpXZ9FbymOHUvXU0JaxETjCq0TXZCLHffcy9iJpzpOtaA@mail.gmail.com>
X-Mailman-Original-References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
 by: Chris Angelico - Thu, 30 Dec 2021 15:23 UTC

On Fri, Dec 31, 2021 at 2:03 AM hongy...@gmail.com
<hongyi.zhao@gmail.com> wrote:
> See here [1] for the related discussion.
>
> [1] https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800

Why did you post in two places at once? Did you need more people to
tell you the same thing as the error message?

ChrisA

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<2a276e53-b385-4323-8631-f92bb8a5df8dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:620a:21d1:: with SMTP id h17mr23615837qka.495.1640903249000;
Thu, 30 Dec 2021 14:27:29 -0800 (PST)
X-Received: by 2002:ac8:5a51:: with SMTP id o17mr28737571qta.180.1640903248846;
Thu, 30 Dec 2021 14:27:28 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 14:27:28 -0800 (PST)
In-Reply-To: <mailman.71.1640877841.3079.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<CAPTjJmpXZ9FbymOHUvXU0JaxETjCq0TXZCLHffcy9iJpzpOtaA@mail.gmail.com>
<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com> <mailman.71.1640877841.3079.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <2a276e53-b385-4323-8631-f92bb8a5df8dn@googlegroups.com>
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 22:27:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 19
 by: hongy...@gmail.com - Thu, 30 Dec 2021 22:27 UTC

On Thursday, December 30, 2021 at 11:24:20 PM UTC+8, Chris Angelico wrote:
> On Fri, Dec 31, 2021 at 2:03 AM hongy...@gmail.com
> <hongy...@gmail.com> wrote:
> > See here [1] for the related discussion.
> >
> > [1] https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800
> Why did you post in two places at once? Did you need more people to
> tell you the same thing as the error message?

Doing so may attract the attention of developers, such as increasing the content of traceback information to make troubleshooting easier, just as André Roberge says here [1].

[1] https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800/6?u=hongyi-zhao

> ChrisA

HZ

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:ac8:5c50:: with SMTP id j16mr29147728qtj.255.1640903571674;
Thu, 30 Dec 2021 14:32:51 -0800 (PST)
X-Received: by 2002:a05:622a:8d:: with SMTP id o13mr28352777qtw.574.1640903571553;
Thu, 30 Dec 2021 14:32:51 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 14:32:51 -0800 (PST)
In-Reply-To: <mailman.70.1640877797.3079.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com> <mailman.70.1640877797.3079.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 22:32:51 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 22
 by: hongy...@gmail.com - Thu, 30 Dec 2021 22:32 UTC

On Thursday, December 30, 2021 at 11:23:35 PM UTC+8, Chris Angelico wrote:
> If it's an exception, it needs to subclass Exception or BaseException.

I see. That is, the following:

class TailRecurseException(Exception):
def __init__(self, args, kwargs):
self.args = args
self.kwargs = kwargs


> (Also, is this REALLY an optimization? Exception handling isn't the
> fastest. Yes, it avoids some measure of recursion depth, but it looks
> like a pretty inefficient way to do things. Python is not Lisp, and
> there are very very few algorithms that actually benefit from tail
> call optimization that wouldn't benefit far more from other ways of
> doing the same thing.)

Could you give some examples of the other methods you mentioned above?
> ChrisA

HZ

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 09:58:47 +1100
Lines: 24
Message-ID: <mailman.72.1640905139.3079.python-list@python.org>
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<CAPTjJmpXZ9FbymOHUvXU0JaxETjCq0TXZCLHffcy9iJpzpOtaA@mail.gmail.com>
<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
<mailman.71.1640877841.3079.python-list@python.org>
<2a276e53-b385-4323-8631-f92bb8a5df8dn@googlegroups.com>
<CAPTjJmoyAcKZm=Nn-Y0r=6cm3ewTRzk6AuekHgn_1+wNFcN5cg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de jN60vmreSB92L3OtgFi1kwGT/j6gpdGC+d0KNwr04sSA==
Return-Path: <rosuav@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=TSns5yxo;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'traceback': 0.04; '31,':
0.05; 'angelico': 0.09; 'attract': 0.09; 'subject:not': 0.09;
'url-ip:184.105.176.44/32': 0.09; 'url-ip:184.105.176/24': 0.09;
'url-ip:184.105/16': 0.09; 'url:discuss': 0.09; 'answer.': 0.16;
'chrisa': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'message?': 0.16; 'received:209.85.128.41': 0.16;
'received:mail-wm1-f41.google.com': 0.16; 'wrote:': 0.16; 'says':
0.17; 'to:addr:python-list': 0.20; 'fri,': 0.22; "what's": 0.22;
'discussion': 0.25; 'chris': 0.28; 'error': 0.29; 'dec': 0.31;
'question': 0.32; 'developers,': 0.32; 'split': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'same': 0.34; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'subject:that': 0.35;
'from:addr:gmail.com': 0.35; 'people': 0.36; 'subject:from': 0.37;
"it's": 0.37; 'received:209.85': 0.37; 'received:209': 0.39;
'two': 0.39; 'tell': 0.60; 'here': 0.62; 'email addr:gmail.com':
0.63; 'increasing': 0.64; '[1]': 0.67; '2021': 0.71; 'attention':
0.71; 'content': 0.72; 'url:t': 0.73; 'easier,': 0.84; 'subject:
\n ': 0.84; 'said.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=UwEYqAfmddlJ/M7PpB6/APbUCiv6MjSvaXGvuq2WLhQ=;
b=TSns5yxoahqxRB70r2+cDwLJsek4ZaEkIvKiG2ZCrAz8kQmVuBCw5mgkavMgk7XcXr
Q+xFWNbL8uqDWC6OlJUAHORdego+KAhkUuu5QilJIr/KWWuMcmS/wkpDTjGQceXQzbl8
O1T06uHJacirhJKLwdpZCxq/AR0nTH7v+HalB1Jm/5yz5ttsGI+LEHYQ/Hp2ucMruAVA
tbBimt5TF0hqIlzBRWXs/RGc2YmMJD7diO+tRqjA8lH5SnhNRH352kuYGsYOz8agGfRv
mzHwxS4ULEX3nKSsOb6Wiq2E/cBn2I9IlICnRqkMj/tUmvQv2QwcyrtHllW/AsReBcaQ
7efQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=UwEYqAfmddlJ/M7PpB6/APbUCiv6MjSvaXGvuq2WLhQ=;
b=JOKpktLAf8zXADCXQvZsHVvKlSXHq5W35eRX00iq0d2GS2FR6IIGUSsPqpD/LSv+aQ
Yb6jfJ13iPKdxXp41gHwF9Nfy9rjJVojvigZ1Ir631EB4l+qGpT+RgHxgDJNmB4fTm2S
fMdVALNiNHpErlBH2GLZqmdrbPWQvzEfOlAsRpnpjAfd8xcW+lDvxz4wq3OXDGqBTE+N
UOEH8wgblixN4vZBQjo/7TLGdYKZ923HGo/gPmDSgVwcsv6T4BMpYtdNEeHt3z3KQqXl
tvc1iioxD4fXHylvvto9PKs0xG3LExPFom1MLdOSu9rjZBpFof0vqMVT8/8p7ozSe/De
pUdQ==
X-Gm-Message-State: AOAM533n5ko28fNBeXxMM72P9ixT5P5eInI1NZ77qjJ2KkFtjkOPwJdr
R0W4RrR+yxDPp0eGPMEZkoDaLwi+TLFCk8v/auzDGCuJ
X-Google-Smtp-Source: ABdhPJw4Zpujr1E1g0p3JfyhqDUFlcI/n1eCavMrGvhpZfXrZ2kq6xsN0AFC81bWSggAhH5JCLMo22Vw/3R3ZVy7nSA=
X-Received: by 2002:a7b:c0d7:: with SMTP id s23mr27966729wmh.135.1640905138031;
Thu, 30 Dec 2021 14:58:58 -0800 (PST)
In-Reply-To: <2a276e53-b385-4323-8631-f92bb8a5df8dn@googlegroups.com>
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: <CAPTjJmoyAcKZm=Nn-Y0r=6cm3ewTRzk6AuekHgn_1+wNFcN5cg@mail.gmail.com>
X-Mailman-Original-References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<CAPTjJmpXZ9FbymOHUvXU0JaxETjCq0TXZCLHffcy9iJpzpOtaA@mail.gmail.com>
<c1f8e807-d1a5-4947-be56-7cdb20514f1dn@googlegroups.com>
<mailman.71.1640877841.3079.python-list@python.org>
<2a276e53-b385-4323-8631-f92bb8a5df8dn@googlegroups.com>
 by: Chris Angelico - Thu, 30 Dec 2021 22:58 UTC

On Fri, Dec 31, 2021 at 9:42 AM hongy...@gmail.com
<hongyi.zhao@gmail.com> wrote:
>
> On Thursday, December 30, 2021 at 11:24:20 PM UTC+8, Chris Angelico wrote:
> > On Fri, Dec 31, 2021 at 2:03 AM hongy...@gmail.com
> > <hongy...@gmail.com> wrote:
> > > See here [1] for the related discussion.
> > >
> > > [1] https://discuss.python.org/t/typeerror-catching-classes-that-do-not-inherit-from-baseexception-is-not-allowed/12800
> > Why did you post in two places at once? Did you need more people to
> > tell you the same thing as the error message?
>
> Doing so may attract the attention of developers, such as increasing the content of traceback information to make troubleshooting easier, just as André Roberge says here [1].
>

It's a simple question with a simple answer. You don't need to
cross-post. All you do is split the discussion so people don't know
what's already been said.

ChrisA

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 10:03:54 +1100
Lines: 37
Message-ID: <mailman.73.1640905447.3079.python-list@python.org>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de FFvHn/VkJN5VA2U96JmZYg8FlpF8OVQAAdG8EXvNuRyQ==
Return-Path: <rosuav@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=hpoGHS6X;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.015
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'looks': 0.02; 'everyone,':
0.03; 'def': 0.04; '31,': 0.05; 'subject:not': 0.09; '(also,':
0.16; 'algorithms': 0.16; 'chrisa': 0.16; 'from:addr:rosuav':
0.16; 'from:name:chris angelico': 0.16; 'received:209.85.221.42':
0.16; 'received:mail-wr1-f42.google.com': 0.16; 'recursion': 0.16;
'wrote:': 0.16; 'python': 0.16; 'instead': 0.17; 'to:addr:python-
list': 0.20; 'exception': 0.22; 'fri,': 0.22; 'code': 0.23;
'anything': 0.25; 'examples': 0.25; "isn't": 0.27; 'local': 0.27;
'function': 0.27; 'wrong': 0.28; 'code,': 0.31; 'dec': 0.31;
"wouldn't": 0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'trying': 0.35; 'handling': 0.35;
'subject:that': 0.35; 'yes,': 0.35; 'from:addr:gmail.com': 0.35;
'subject:from': 0.37; 'really': 0.37; 'received:209.85': 0.37;
'way': 0.38; 'could': 0.38; 'received:209': 0.39; 'single': 0.39;
'mentioned': 0.39; 'methods': 0.39; 'neither': 0.39; 'wants':
0.40; 'try': 0.40; 'skip:o 10': 0.61; "there's": 0.61; 'email
addr:gmail.com': 0.63; 'down': 0.64; 'process.': 0.65; 'benefit':
0.65; 'shows': 0.67; 'bad': 0.67; 'please,': 0.67; '2021': 0.71;
'signature': 0.76; 'subject: \n ': 0.84; 'beauty': 0.91;
'optimization': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=YiuQ+HARUkkSZ0m9EUyz6zZYVi17eofrXnZo91fUJUQ=;
b=hpoGHS6XbxTC+BXPLDvjHAdZfzlMDAVoHqCPaf0WeSbZQgYZ/o88+AhDStfpwhCL+E
RJqOTk3dyWRYDXOCdHwNLSuNRdYZLySLwO3OrFy5UWJAHueR5A2FWkfQcPakEtMOLewe
sXjCwrw//61C9ujJZWDtiNTh3+ih6Fa7CYm3GoVhNJYQwOEpU1FPoA+ItPmfY4SGYTAN
Jn2SdFBOhTKtxapbOiy6WDT9O1Bea1lChbTGbMGnOa21LOMgALZWqwIZvk5m7J9Iq8CF
pZQ9tPM6HMt7KQFlznHiFYVYM3hpSlwcPH8I+8NSj0re8KfnMhD2g1BaR1N9fKyXodgm
FXyA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=YiuQ+HARUkkSZ0m9EUyz6zZYVi17eofrXnZo91fUJUQ=;
b=xz9yD4kX060aGbxc0u4kgJJzzx3EHXuYpffy+Va4o4Ct5Fi5jLC6smWJo5oebCnJvd
NJNoqmrf9KnQppshnQf40Vif/OqgyXmMBkCdg6I+dDWLXjLNphUZwUIaSXkMwYxHtJEs
7NPV47ubG0SKxpa0gkNSkdhyanWas0Eq5vGPuEZRUc9ajpmXoGwXhDyBirDiWUbLFkBx
lJdWfn8L2dIofZNrPiW8NCsetjLtPowMB7zbPaCdh5LqPg4MWkdAFh0bTx79JnS9zG4I
zXlX30rODYCaeTYH9VmxeOp0DW2YYVfmr6ZFsJIYcHgrX/lp0Ckp3lV6/CzlmlWMWvRB
Fedg==
X-Gm-Message-State: AOAM532qyf38br8mcIhldXug1ISQLr0VtkHqcz30HvF4t5KdraZLFI4M
BHuNy1T78jYDgk2sqgQQtd2qODj58g8mDWTB8uw6ka98
X-Google-Smtp-Source: ABdhPJxzcwXEkIECwjTvyTSIYrvdBwMSspF4rLfzxSc/Lepd/ZXSbRheDc7zQPPdVSpfoMJcSuumi86MnG8TGsuJRYw=
X-Received: by 2002:a05:6000:156c:: with SMTP id
12mr26353904wrz.104.1640905445656;
Thu, 30 Dec 2021 15:04:05 -0800 (PST)
In-Reply-To: <170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
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: <CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
X-Mailman-Original-References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
 by: Chris Angelico - Thu, 30 Dec 2021 23:03 UTC

On Fri, Dec 31, 2021 at 9:42 AM hongy...@gmail.com
<hongyi.zhao@gmail.com> wrote:
> > (Also, is this REALLY an optimization? Exception handling isn't the
> > fastest. Yes, it avoids some measure of recursion depth, but it looks
> > like a pretty inefficient way to do things. Python is not Lisp, and
> > there are very very few algorithms that actually benefit from tail
> > call optimization that wouldn't benefit far more from other ways of
> > doing the same thing.)
>
> Could you give some examples of the other methods you mentioned above?
>

If you have a function that has just a single tail call site, there's
usually no point writing it recursively.

def factorial(n):
ret = 1
for i in range(1, n + 1): ret *= i
return ret

def fibonacci(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a

Neither of these wants to be recursive, and writing them recursively
pollutes the function signature with parameters that really exist just
to be local variables. Passing an accumulator down is a terrible way
to demonstrate the beauty of recursion - it instead shows off how you
can shoehorn anything into recursion and make it worse in the process.

Please, everyone, stop trying to optimize the wrong things.

Write good code, don't try to make bad code stop crashing.

ChrisA

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:ad4:5bc9:: with SMTP id t9mr29745180qvt.70.1640906838730;
Thu, 30 Dec 2021 15:27:18 -0800 (PST)
X-Received: by 2002:a05:6214:2aab:: with SMTP id js11mr29341167qvb.54.1640906838608;
Thu, 30 Dec 2021 15:27:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 15:27:18 -0800 (PST)
In-Reply-To: <mailman.73.1640905447.3079.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com> <mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com> <mailman.73.1640905447.3079.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 23:27:18 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 9
 by: hongy...@gmail.com - Thu, 30 Dec 2021 23:27 UTC

On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote:
> Neither of these wants to be recursive, and writing them recursively
> pollutes the function signature with parameters that really exist just
> to be local variables. Passing an accumulator down is a terrible way
> to demonstrate the beauty of recursion - it instead shows off how you
> can shoehorn anything into recursion and make it worse in the process.

Then what cases/scenarios can demonstrate the beauty of recursion?

HZ

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<87fsq9slok.fsf@nightsong.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed
Date: Thu, 30 Dec 2021 15:43:55 -0800
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <87fsq9slok.fsf@nightsong.com>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<mailman.73.1640905447.3079.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="2f1173641a694aa6897296ee372b5fcf";
logging-data="28945"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18d0xK/nSPk2SGtmRk2NOfv"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:L4ieJdqloPA8W2hf5DWZBcrdxnU=
sha1:cxg+ElEdF6Qlxqyt4xmsVzl8YUs=
 by: Paul Rubin - Thu, 30 Dec 2021 23:43 UTC

Chris Angelico <rosuav@gmail.com> writes:
> writing them recursively pollutes the function signature with
> parameters that really exist just to be local variables.

It's idiomatic in a coding style that considers non-constant variables
to be problematic in their own right. Of course you can use an
auxiliary function to get rid of the extra parameter to the outer
function. I don't see the GP post so I don't know if the posted example
did that. Anyway, one can at most say that traditional Python style
prefers variables and loops to recursion. Others like to say: "to
iterate is human; to recurse, divine". ;-)

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Thu, 30 Dec 2021 23:50:20 +0000
Lines: 11
Message-ID: <mailman.75.1640908231.3079.python-list@python.org>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de NK5G8kdNUxcPgI3IcvksdgQ1tnZTDQNVBihnw1FECRYw==
Return-Path: <python@mrabarnett.plus.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=plus.com header.i=@plus.com header.b=UxTHVWYO;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.015
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '31,': 0.05; 'angelico':
0.09; 'from:addr:python': 0.09; 'received:192.168.1.64': 0.09;
'subject:not': 0.09; 'from:addr:mrabarnett.plus.com': 0.16;
'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:84.93': 0.16; 'received:84.93.230': 0.16;
'received:plus.net': 0.16; 'recursion': 0.16; 'wrote:': 0.16;
'instead': 0.17; 'to:addr:python-list': 0.20; 'anything': 0.25;
'friday,': 0.26; 'local': 0.27; 'function': 0.27; 'chris': 0.28;
'header:User-Agent:1': 0.30; 'received:192.168.1': 0.32; 'header
:In-Reply-To:1': 0.34; 'subject:that': 0.35; 'subject:from': 0.37;
'really': 0.37; 'received:192.168': 0.37; 'way': 0.38; 'neither':
0.39; 'wants': 0.40; 'email addr:gmail.com': 0.63; 'down': 0.64;
'process.': 0.65; 'shows': 0.67; '2021': 0.71; 'signature': 0.76;
'subject: \n ': 0.84; 'beauty': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1640908223; bh=fqwdev6rXehhBWupRfiWsuJyoxuTxOWpxwyn9ptW6dE=;
h=Date:Subject:To:References:From:In-Reply-To;
b=UxTHVWYO5JAmehyQMnOlsrNT0+e/AZRH8L96umgj4noNpcRbqms+8VmBSzvW5cJ1e
Vqt7qKkX4wM0OgARY1xLptD6OkGC+cUV/6upRHB1AStCptml9RHMDhcTy4zEzSGTHR
Hx5w6XIXSTKxziaEL5I1x1tW6081CyibGA6qEZaqervjxh0DpYRXb9r0NssIlU39Vo
Sy57KmXv0eupNh0ui09S7VzWwhbSwDsp2a79w7/IfVI4qx+KblT/fVtCYnI0YR3Gf6
h8d9qu8Zdyd8725vJxS4Pqn+cR5sGcPSCBNvDKyeGATmI4c47olr++gjOXY2oNSrAN
iHJ7MG7sch0/w==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=OeX7sjfY c=1 sm=1 tr=0 ts=61ce45bf
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=UkO4QJc3TulOnKW-sokA:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.1
Content-Language: en-GB
In-Reply-To: <df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
X-CMAE-Envelope: MS4xfKMe+GTcL4kOY01B2tY6HGSPfHCQuDVGRkTXsdqRR2ngy4aj/wnGJy0CEt25pnbVS1lcy1UFjWxPjRiLlHkjRUnFmOdgc72j4t1ExxXrVzOJXfVGlBed
HnvO/RKzIxvPtA0FbK5aFQA4BxYrFeeC86v/3aMhhmZv+f2HmD1Rku9nI4u9rAhBerYP+WKR6sTmKHaqYeWwlEOeBi1spuvRKKw=
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: <2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
X-Mailman-Original-References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
 by: MRAB - Thu, 30 Dec 2021 23:50 UTC

On 2021-12-30 23:27, hongy...@gmail.com wrote:
> On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote:
>> Neither of these wants to be recursive, and writing them recursively
>> pollutes the function signature with parameters that really exist just
>> to be local variables. Passing an accumulator down is a terrible way
>> to demonstrate the beauty of recursion - it instead shows off how you
>> can shoehorn anything into recursion and make it worse in the process.
>
> Then what cases/scenarios can demonstrate the beauty of recursion?
>
Walking a tree.

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

<661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
X-Received: by 2002:a05:6214:23ca:: with SMTP id hr10mr29980023qvb.82.1640908645509;
Thu, 30 Dec 2021 15:57:25 -0800 (PST)
X-Received: by 2002:a05:622a:1902:: with SMTP id w2mr29458820qtc.498.1640908645355;
Thu, 30 Dec 2021 15:57:25 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.python
Date: Thu, 30 Dec 2021 15:57:25 -0800 (PST)
In-Reply-To: <mailman.75.1640908231.3079.python-list@python.org>
Injection-Info: google-groups.googlegroups.com; posting-host=203.175.13.154; posting-account=kF0ZaAoAAACPbiK5gldhAyX5qTd3krV2
NNTP-Posting-Host: 203.175.13.154
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com> <mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com> <mailman.73.1640905447.3079.python-list@python.org>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com> <mailman.75.1640908231.3079.python-list@python.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
From: hongyi.zhao@gmail.com (hongy...@gmail.com)
Injection-Date: Thu, 30 Dec 2021 23:57:25 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: hongy...@gmail.com - Thu, 30 Dec 2021 23:57 UTC

On Friday, December 31, 2021 at 7:50:48 AM UTC+8, MRAB wrote:
> On 2021-12-30 23:27, hongy...@gmail.com wrote:
> > On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote:
> >> Neither of these wants to be recursive, and writing them recursively
> >> pollutes the function signature with parameters that really exist just
> >> to be local variables. Passing an accumulator down is a terrible way
> >> to demonstrate the beauty of recursion - it instead shows off how you
> >> can shoehorn anything into recursion and make it worse in the process.
> >
> > Then what cases/scenarios can demonstrate the beauty of recursion?
> >
> Walking a tree.

There are many type of trees. Do you mean all of them?

RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigross@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: RE: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Thu, 30 Dec 2021 19:10:57 -0500
Lines: 73
Message-ID: <mailman.76.1640909463.3079.python-list@python.org>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<014601d7fdda$e2dcad90$a89608b0$@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de wKCrCMTQIzIx+ER7MpN3IwZHnpWO/M3mQgBLKejJ3Z0w==
Return-Path: <avigross@verizon.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=verizon.net header.i=@verizon.net header.b=hPAi8ZSP;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.008
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'looks': 0.02; '31,': 0.05;
'parallel': 0.05; 'angelico': 0.09; 'branches': 0.09;
'comparison': 0.09; 'float': 0.09; 'int': 0.09; 'neat': 0.09;
'routines': 0.09; 'subject:not': 0.09; 'steps': 0.11; 'log': 0.12;
'url:mailman': 0.15; 'memory': 0.15; 'that.': 0.15; 'algorithms':
0.16; 'are.': 0.16; 'cases,': 0.16; 'dividing': 0.16; 'few.':
0.16; 'mathematical': 0.16; 'reality.': 0.16; 'received:(vzm
hermes smtp server)': 0.16; 'recursion': 0.16; 'recursion,': 0.16;
'run-time': 0.16; 'similarity': 0.16; 'sorted': 0.16; 'tree,':
0.16; 'wrote:': 0.16; 'python': 0.16; 'larger': 0.17;
'applications': 0.17; 'instead': 0.17; 'calls': 0.19; 'hardware':
0.19; 'to:addr:python-list': 0.20; 'machine': 0.22; 'returns':
0.22; 'teach': 0.22; 'run': 0.23; '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; 'binary':
0.26; 'classes': 0.26; 'friday,': 0.26; 'local': 0.27; 'bit':
0.27; 'function': 0.27; 'done': 0.28; 'chris': 0.28; 'mostly':
0.28; 'sense': 0.28; 'keeping': 0.28; 'modify': 0.31; 'url-
ip:188/8': 0.31; 'think': 0.32; 'half': 0.32; 'negative': 0.32;
'python-list': 0.32; 'returning': 0.32; 'unless': 0.32; 'but':
0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'book': 0.35;
'complex': 0.35; 'subject:that': 0.35; 'track': 0.35; 'yes,':
0.35; 'subject:from': 0.37; 'really': 0.37; 'using': 0.37;
'others': 0.37; 'way': 0.38; 'read': 0.38; 'two': 0.39; 'enough':
0.39; 'use': 0.39; 'methods': 0.39; 'neither': 0.39; 'advantage':
0.40; 'base': 0.40; 'place.': 0.40; 'wants': 0.40; 'something':
0.40; 'want': 0.40; 'from:': 0.62; 'to:': 0.62; 'here': 0.62;
'come': 0.62; 'true': 0.63; 'email addr:gmail.com': 0.63;
'simply': 0.63; 'skip:b 10': 0.63; 'down': 0.64; 'becomes': 0.64;
're:': 0.64; 'times.': 0.64; 'your': 0.64; 'process.': 0.65;
'numbers': 0.67; 'shows': 0.67; 'right': 0.68; 'items': 0.68;
'matter': 0.68; 'and,': 0.69; 'compare': 0.69; 'showed': 0.69;
'2021': 0.71; 'little': 0.73; 'costs': 0.74; 'signature': 0.76;
'sent:': 0.78; 'depth': 0.81; 'catching': 0.84; 'handled': 0.84;
'horrible': 0.84; 'inherit': 0.84; 'really.': 0.84; 'beauty':
0.91; 'seemingly': 0.93; 'unlimited': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1640909460; bh=PrZbvllWi2XoBwkhf0596+w+0MgvVd7p/wCkY6VfLms=;
h=From:To:References:In-Reply-To:Subject:Date:From:Subject:Reply-To;
b=hPAi8ZSPI1UkX5Y8kpTM6fLpwBjyiQKLWc1WH9KiPo1EYCis2gBtq9QYHqqsL9MYaulzAUhcqktj8Y5l/XpxMasKkPPTRU3Dx+UZXWjaFspiNkGeypqHhfWuUYfQ4dIFMRr7qGiZdPBBsc5LfBoK2CXHfyZJa5phR2AHFlXyCNGRPDHxCnkfpdQEvlwBzUEBX9c5otCE33wWcW+X6bICByL3zaNZc2eluJe4B+Fe5fznsD6MqvkrHDy1oYrFSShFA8GMxE6ec6Vbt1cLumoDS9H8hKd0hqTNwmYMOdYDtDJfa8VJvmcj5npx8dU+w6EjCl+A0ITUoWshj0p3dBnx6A==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1640909460; bh=qgYBXc0iB8NzLbcXKnuk+OLod8CCECdeoz4qP/cCDc9=;
h=X-Sonic-MF:From:To:Subject:Date:From:Subject;
b=HTpECfYUmpWy8woWWR4hR8zgNWDuAfdKHa3SuChVUcNjuEWFuYwg5LS6WOWZCg9KDRntwlsgCcjFf/eHIxJYe65fVo/BnpeY7eWMcRiM7SPLrw6DtLNCem2px1i5Ige/mRTfOxLDiGPuK2cYvhTtdCCEStt0DpuuZ4JnqapAeIp9My0dJXPD2STqRlMItaIKuBflnPqXO4P0gHR6fp7XtjH3X+uR3Ar1zu19I8Ow5GiE0yc7lIZVZMkh+2AqKkvw47taRkp1wJlPZElQu1vCOHyqFovqbmyGRmzENgcyFPEOFqPjbmgUVhgkPoh6jnlQYndG9w1JGRhWqxqrYVU2uQ==
X-YMail-OSG: 7Iu3rboVM1m43asM8bvf4czBiBItdO7kn5bzhkU_7BYkbxzphrnbhMEsH7LE4Np
GhDFi3erHPjlpEw_HGGx_lhmINNgc9fvtzN7QzbgM6Bg9iM9.vmDFPOWIktDsghLdUnEzAE0UEN7
coPjI_Rvxd9rLGZhZ_JUvPy1kt_xfFzAp45.rzJmCDtP5Z9yt.Y3qSHgojp1KDNHnBan452DGtbU
3XjO7VoT0iQoS5X3ZMuxCX8zE_JhYhf.rp.7tQ5p99B.A3MRLDyNFMs6rD7ajDqBi154qpJ_u7lw
3y70y3ErqgT4PIk_Tlrq_pEnYy4HmNOb6rRa3jaf9X3bdEjlBaIraANsH_nPxnmrQvvUnJA0Yx7c
9wjmbLQEJPW71.StqbDGatDO9Y6m0i9JJ9uOBz_t_ef83__11SME7VODEnezCcWxUYSCGM3AzMSk
Evr6zguNOT8dwNICM7MEIr_yyFLejADtriztISyJzQ4ejmmD_88p.uI9Pi2PlFuFSK3EoCdw91Ix
CoQEThRNwOn6z5vZUltrfs0un2Kb.hvnKSWKijaAV1EkCewInmymjD6LdrKPSB2ZzQ3yvqlcAnAN
FgXlx55WlsP_BbHRk8PYEJa5wc9iUFu__JRolA3_oyuH11y9ma5N0scb0RXL.o7nrsKxe9MKUFNQ
HG8wE4nNFq72OHSpI1ppDGSK9ucrpG0Yo9M_.sdI4u9x_uavB.cZIHeCPnWV_Rku30jYe_axqoBw
ha8DclSclXFJbzjNJfg0kgRbSvkKd382goLg.yQgSpxT7wIld1GLlMWwqDywZeZcOwrLDSOJAFta
h7QrHxl3GinT0DkpgD4mp9.wmnaBfVs0HtpUsYrsjKzIc1cmGmGJBJFVPvrqsvjuDjkC_QfAAgog
CN8JCoJgwey_iPh7E2Ma7j0MNgTVrJLXP7K0XIeP.fvd1aM1LFB8C_sDBNRGwNSuM2eZamZKDwx4
Ys4bQ6Bpgd90nPM5LiRC4Okp7eN3EDbEZDLMX5RIz96598C55aMrRke71iXkWOmiTx4DwZj358vN
7xfagsv2quDJWJaGUNGMR48UUmZVgQx8jNYC9N7s9QpNKv4Cg4p4o47FcfOSUmlBAhIfn_PD0afS
ewWEEKKVTe8ola5peWxF8st8MPKatm.TmLswQ7MKgIAu4LHG.2K5bnAD3aciJv6hoSGBOKMp2lHE
GAiYISsmZ3NAibIpg.Mv0YIDv.VppCObmxMEj4DkxDErEs_sYILzwbkMarfopM8h.bh7Jwu92jxz
lxk1yFKTXDaJmH3RoyZbah9FldMqrig8Gid1QGPawf8sgRtg8eO.q6VVDGFuW4LUduRVKlhBmkuN
wBiEjGjEeErg1LDUvv6OsN5.UTxB8mAjWFiP.Vgl5ro1yQi3eGeyL.N4vqB3TJxgo4ejh9HSv836
VjAyWiws5zzzrfNOuuMiMUHFYpyV.4ahC8BK6xLMkL1Yp4k_srrpjqIWaxFLgOR3mD0I2aqYbNaK
rfsP99x_WuCzynoPL76K3cxIKmVWKPh7HcEWeUSi4RQ2ivcUK.dgSI59IZAqolnrY4wlus08oVIp
cPMajWKzn1MugJHnOkCA0cYDfd._ews5n8Um.8aMzn_mGLe1Q6xx371tari9XVQnid0aPgvbViSr
FFfPjc8DgNAW7R_kmp6ReHRBRVoQOQN03XnkiKwm3DJtFiZkZvDEmHDvUKQCAKXcHmPn11zQ.Hdg
qGLRY1gzK.RVaS0HKfhG8Igu.JDdYrazkrczj7Ix1zFDvttwc619fFlJq6CbEFFr3Pqi3XxlmbCJ
W7NaawmVnqd0Iom_GO.9kbw_aaO.yEQctiHbQ09NYoK1EvreBQZH8MJusWKPGaqtjCDh5p5sL.yT
n10g1iq45lnsAW.EUDt0mha7BH02DKraStSbBpb40aXpB.NX.hrsfgO3HCgwjNqrCEI.ECSh9Rb4
hjcs1QugukkafZ7gm2TQ2B1RC3YMFUnfQxy3FefGCmFKVDriT6vIILo4J7MCJ1ENxOFsZlfxgcrR
CWoUcq7N0rIrKJGTU01E_DkaXsxIwzUpKiao9q0Ufn7rr8VCZgJXBP_BVty7xV22sFllHjQHja2Y
8j79Ksoxnkf2lrvjlUrbS3w9dyyYu8WZTugVpojERYLoIXUw27Y7JpEOv6IN2m68NAZr7hP_wXB1
yDRM5r5pAhgllO4nCJB1BiomGy7sbw.Ie9hBADRjeWQ--
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQJJLGXRjr/qUuE4Z8QAhSCkRxWHrgMTLMBFAs9lEjIB+f9UigKCLfGRAkbxZ80B3klElqr1OGBw
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: <014601d7fdda$e2dcad90$a89608b0$@verizon.net>
X-Mailman-Original-References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
 by: Avi Gross - Fri, 31 Dec 2021 00:10 UTC

Beauty of Recursion?

Well, there is what I call Mathematical Beauty, and then there is reality.

It is fantastic to prove neat theorems that something is possible by methods
like mathematical induction that in some sense use recursion as in if
something is true for some base value and it can be shown that if it is true
for N then it also is true for N+1, then by a sort of recursion, it is true
for every larger value!

And, yes, you can write some seemingly neat and compact routines using
recursion, but there are many run-time costs as Chris and others can
suggest.

Where is recursion most useful? I can think of many places but will briefly
mention a few.

There is a recursive sort algorithm that keeps dividing the data it is
handled in two and calls itself recursively to process the first half and
then again on the second half and simply merges the sorted results and
returns that. Clearly this kind of algorithm calls itself to a depth of
about log to the base two times. And a possible advantage here is that this
can take some advantage of parallel architectures and some simultaneity.

Another general set of recursive applications is anything that wanders
tree-structures and looks for items or places new items in an appropriate
place. If it is a binary tree, there is a slight similarity with my first
example as there is a do_left and a do_right type of recursion but not
really. And of course trees can have more than two branches and you can use
recursion on other complex structures. But in some cases, you can come up
with a non-recursive way to do things by keeping track of where you are and
where you have been.

Recursion is a good thing to teach but also a horrible thing when misused. A
book I read decades ago, called The Little Lisper, showed algorithms such as
asking for greater(A, B) to be done sort of like by recursively calling
greater(subtract1(A), subtract1(B)) as long as neither A nor B becomes zero.
Neat algorithm and tolerable for greater(3,5) returning 5 after a few
recursions when 3 has been lowered to zero. Not so good with negative
numbers. But greater(10000000000, 10000000001) might take a while and your
machine may run out of memory and since you want to return the original
value, tail recursion may not be enough unless you modify things a bit such
as using a helper function that also includes the original numbers so it
returns the right one or ...

Many machines simply restrict you to compare numbers only up to the point
where an int or float of some kind support it and then the operation of
comparison is mostly just done in a few steps in the hardware no matter what
size the two things are. Python with support for unlimited size integers
though, ...

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of hongy...@gmail.com
Sent: Thursday, December 30, 2021 6:27 PM
To: python-list@python.org
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed

On Friday, December 31, 2021 at 7:04:24 AM UTC+8, Chris Angelico wrote:
> Neither of these wants to be recursive, and writing them recursively
> pollutes the function signature with parameters that really exist just
> to be local variables. Passing an accumulator down is a terrible way
> to demonstrate the beauty of recursion - it instead shows off how you
> can shoehorn anything into recursion and make it worse in the process.

Then what cases/scenarios can demonstrate the beauty of recursion?

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

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Marco.Sulla.Python@gmail.com (Marco Sulla)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 09:17:29 +0100
Lines: 103
Message-ID: <mailman.77.1640938688.3079.python-list@python.org>
References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<CABbU2U_Rg5XZk6hfQJMbpJDVsqLBzAhGLJSzEb=_e=UBSObc0Q@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de TS3LNcU+Q3KN9r9Geha7ywBZoryVR9ASuA8124uFBXnQ==
Return-Path: <elbarbun@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=G0bp1L4T;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'pip': 0.04;
'traceback': 0.04; '(most': 0.05; 'last):': 0.05; 'fake': 0.07;
'"""': 0.09; 'cc:addr:python-list': 0.09; 'compute': 0.09;
'else:': 0.09; 'fails': 0.09; 'prints': 0.09;
'received:209.85.219': 0.09; 'skip:@ 20': 0.09; 'subject:not':
0.09; 'typeerror:': 0.09; 'url-ip:151.101.0.223/32': 0.09; 'url-
ip:151.101.128.223/32': 0.09; 'url-ip:151.101.192.223/32': 0.09;
'url-ip:151.101.64.223/32': 0.09; 'cc:no real name:2**0': 0.14;
'import': 0.15; 'url:mailman': 0.15; '"calculate': 0.16; '16:00,':
0.16; '3.9.1': 0.16; 'context.': 0.16; 'derive': 0.16;
'from:name:marco sulla': 0.16; 'hints': 0.16; 'implements': 0.16;
'kwargs)': 0.16; 'next,': 0.16; 'python3.': 0.16; 'recall': 0.16;
'recursion': 0.16; 'script,': 0.16; 'stack.': 0.16; 'url:project':
0.16; 'url:pypi': 0.16; 'wrote:': 0.16; 'problem': 0.16; 'python':
0.16; 'thu,': 0.19; 'cc:addr:python.org': 0.20; 'exception': 0.22;
'skip:_ 10': 0.22; 'install': 0.23; 'code': 0.23; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'cc:2**0': 0.25; 'url-ip:188.166/16': 0.25;
'classes': 0.26; 'function': 0.27; 'error': 0.29; 'dec': 0.31;
'raise': 0.31; 'url-ip:188/8': 0.31; 'program': 0.31; "doesn't":
0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32;
'appreciated.': 0.34; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'handling': 0.35; 'subject:that':
0.35; 'following': 0.35; 'from:addr:gmail.com': 0.35;
'subject:from': 0.37; 'received:209.85': 0.37; 'class': 0.37;
'file': 0.38; 'received:209': 0.39; 'try': 0.40; 'skip:o 10':
0.61; 'above': 0.62; 'url-ip:151.101.0/24': 0.62; 'url-
ip:151.101.128/24': 0.62; 'url-ip:151.101.192/24': 0.62; 'url-
ip:151.101.64/24': 0.62; 'here': 0.62; 'email addr:gmail.com':
0.63; 'skip:b 10': 0.63; 'number,': 0.64; 'skip:t 20': 0.66;
'shows': 0.67; 'url:q': 0.67; '[1]': 0.67; 'during': 0.69;
'fixing': 0.69; '2021': 0.71; 'skip:f 20': 0.75; 'highly': 0.78;
'big,': 0.84; 'catching': 0.84; 'converted': 0.84; 'exceptions':
0.84; 'inherit': 0.84; 'subject: \n ': 0.84; 'optimization': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=s/YlMNffbTBlVONrWQ7HSqRQ7yb4C2/jnMOz8qM54SM=;
b=G0bp1L4TJjMnL9fPHnQVs7RT7Yxj4V512FUMrQrfHbXklsOv/yx0Me81gV2+2qNLHV
1Qi6KRChEdHlLVZhlqL2/YEED1YTJriC9GnNssTlUom+L5WGDxcSSaRx+210E2pqKlIh
ANTuJQKA01nWc0p7XKeOi10zP9nIUd3ukL1gEj7XhbCEYDjdDchDAGI5xmAzrIwxGd6J
fNgtnSkx53BH26WWPlgAFJKsvypvuHVbVzZihmRjbagu/gRBkfqZl+tl4OYC9T+REmK2
jYvsGYi/3GJAYqZ1hSm25O7I3YHVtw+5VDMiCGLNnBd9w06F+fW+CzRbelgS1WY5dXrf
HGbA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=s/YlMNffbTBlVONrWQ7HSqRQ7yb4C2/jnMOz8qM54SM=;
b=P5BWo1SXo+mnAx/LZXNcdvnD0YhtFaGF2b6/sSPx6c3WCcRX4IbHti35RSag/4jmUO
Z/+//Yyp0sJI9HihmG/r+VYJKSyPXpA/0rF2/fC0Wf85TtveBnGtG/s6GK6ET174Kqds
n2L+fBvLzxRzsjnz8lTZv3qHXjFrT+dPFFoMRY+WvUHiNwcTJmN8cRJLiFFJo5wGlk5+
BGLp1vghsJEGf5frVo61vyZN7HUVtUNxKLLkvTB9cGDlvPOxQkr8f5SW2dSVC66DS4L8
lcIL3ZQpGvTbs40X7PrzGaPDaaeFf/uQ0p2hU1/pBdbrTj6QnFO0gd2xz4qqGs7r9egG
OKVg==
X-Gm-Message-State: AOAM531+9FZabAM+syLATCqDd5BxC5r1bPdmrbDQPgdU57Ldps6Cqd/c
91KHVHz+29QZTy0iqw3AbfG5Iy/f+LRCCyyq/QIHZdYQlEM=
X-Google-Smtp-Source: ABdhPJyKc/k/zfRiUiQ76UMPcPNEuj9gCRZ5GYe202erz/53iQWVKsSTr5yTbX+v3V1MPRHkUF1ZdZbzmjB525Whqz0=
X-Received: by 2002:a25:8a:: with SMTP id 132mr27233348yba.738.1640938686047;
Fri, 31 Dec 2021 00:18:06 -0800 (PST)
In-Reply-To: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
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: <CABbU2U_Rg5XZk6hfQJMbpJDVsqLBzAhGLJSzEb=_e=UBSObc0Q@mail.gmail.com>
X-Mailman-Original-References: <d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
 by: Marco Sulla - Fri, 31 Dec 2021 08:17 UTC

It was already done: https://pypi.org/project/tail-recursive/

On Thu, 30 Dec 2021 at 16:00, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
>
> I try to compute the factorial of a large number with tail-recursion optimization decorator in Python3. The following code snippet is converted from the code snippet given here [1] by the following steps:
>
> $ pyenv shell datasci
> $ python --version
> Python 3.9.1
> $ pip install 2to3
> $ 2to3 -w this-script.py
>
> ```
> # This program shows off a python decorator(
> # which implements tail call optimization. It
> # does this by throwing an exception if it is
> # its own grandparent, and catching such
> # exceptions to recall the stack.
>
> import sys
>
> class TailRecurseException:
> def __init__(self, args, kwargs):
> self.args = args
> self.kwargs = kwargs
>
> def tail_call_optimized(g):
> """
> This function decorates a function with tail call
> optimization. It does this by throwing an exception
> if it is its own grandparent, and catching such
> exceptions to fake the tail call optimization.
>
> This function fails if the decorated
> function recurses in a non-tail context.
> """
> def func(*args, **kwargs):
> f = sys._getframe()
> if f.f_back and f.f_back.f_back \
> and f.f_back.f_back.f_code == f.f_code:
> raise TailRecurseException(args, kwargs)
> else:
> while 1:
> try:
> return g(*args, **kwargs)
> except TailRecurseException as e:
> args = e.args
> kwargs = e.kwargs
> func.__doc__ = g.__doc__
> return func
>
> @tail_call_optimized
> def factorial(n, acc=1):
> "calculate a factorial"
> if n == 0:
> return acc
> return factorial(n-1, n*acc)
>
> print(factorial(10000))
> # prints a big, big number,
> # but doesn't hit the recursion limit.
>
> @tail_call_optimized
> def fib(i, current = 0, next = 1):
> if i == 0:
> return current
> else:
> return fib(i - 1, next, current + next)
>
> print(fib(10000))
> # also prints a big number,
> # but doesn't hit the recursion limit.
> ```
> However, when I try to test the above script, the following error will be triggered:
> ```
> $ python this-script.py
> Traceback (most recent call last):
> File "/home/werner/this-script.py", line 32, in func
> return g(*args, **kwargs)
> File "/home/werner/this-script.py", line 44, in factorial
> return factorial(n-1, n*acc)
> File "/home/werner/this-script.py", line 28, in func
> raise TailRecurseException(args, kwargs)
> TypeError: exceptions must derive from BaseException
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "/home/werner/this-script.py", line 46, in <module>
> print(factorial(10000))
> File "/home/werner/this-script.py", line 33, in func
> except TailRecurseException as e:
> TypeError: catching classes that do not inherit from BaseException is not allowed
> ```
>
> Any hints for fixing this problem will be highly appreciated.
>
> [1] https://stackoverflow.com/q/27417874
>
> Regards,
> HZ
> --
> https://mail.python.org/mailman/listinfo/python-list

Re: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: Karsten.Hilbert@gmx.net (Karsten Hilbert)
Newsgroups: comp.lang.python
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Fri, 31 Dec 2021 13:08:58 +0100
Lines: 13
Sender: <karsten.hilbert@gmx.net>
Message-ID: <mailman.78.1640952542.3079.python-list@python.org>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<mailman.75.1640908231.3079.python-list@python.org>
<661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
<Yc7y2uhvqI9BTxhv@hermes.hilbert.loc>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 8AWCYYybWwDwbKqkvXn/+Q71YPLWDiLAy/BighFq7FVw==
Return-Path: <karsten.hilbert@gmx.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=gmx.net header.i=@gmx.net header.b=fRP8onhJ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:212.227': 0.07;
'gpg': 0.09; 'karsten': 0.09; 'schrieb': 0.09; 'subject:not':
0.09; '-0800': 0.16; '1713': 0.16; 'received:212.227.15': 0.16;
'recursion': 0.16; 'them?': 0.16; 'trees.': 0.16; 'thu,': 0.19;
'to:addr:python-list': 0.20; 'dec': 0.31; 'there': 0.33; 'mean':
0.34; 'header:In-Reply-To:1': 0.34; 'subject:that': 0.35;
'subject:from': 0.37; 'much.': 0.39; 'received:212': 0.62; '2021':
0.71; 'subject: \n ': 0.84; 'beauty': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net;
s=badeba3b8450; t=1640952539;
bh=JH3VfgkKnTynafn7HJNnyN4ccCmH5Y3qcnKADP22LNk=;
h=X-UI-Sender-Class:Date:From:To:Subject:References:In-Reply-To;
b=fRP8onhJwOEeLb8iP93SmJMH0gKrZY7X6Gp0jkYfpPjXFNQwRS4cN7XOcsrj+U0BU
ophG0QOAUP/V836SsvtVWY4hLJljEgdoRLgDBU7cb8U7hlSm3RWYZqzmA04Xf2MlVD
TYrawDlVH6eGzoVixPhQqKnbCvS78dTn2ViOrCrE=
X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c
Content-Disposition: inline
In-Reply-To: <661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
Ma_X_il-Followup-to: d
Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net
Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net
X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net
X-Pri_X_ority: 2 (High)
X-Provags-ID: V03:K1:YlF6duZ3M3lHSazCOtUJiRf9XjN8tETcvBplWS51oq/j+NlevrC
Ps/K5k7a+rOSoxEnv0qi2dNEpVuNBTHyOG4MlrchT/PG0wduSSMHVjj7WbTqCui0Z6pylkm
ieGO7LYPHRbNkxluBOCMmG/vHvLNDD2UhwWRvSse2n80QCb2A9c5KNMKR9oKLjI3fnZWcL6
w+e6810BWCo6R0M2OGvxg==
X-Spam-Flag: NO
X-UI-Out-Filterresults: notjunk:1;V03:K0:5Fpgg0YEJ6Y=:APmqyqvqa403NywIr9Ltjb
gD3pXY0uAQADQVrWETkfqX+IyteVYS+1pRjniTIU6vjL4kbcttJ53x50yrEWgEa2M3P+Vh/Ib
26GBf6Ok3WuK2nmNsopxZb6clVEE2na/sGn/IAIQXPmjeha3DoQyO4P+qRibYufnNqBnXcDWp
LHSStL7Ft2f9zkFG3tEvfpNuXOaD4UCng/2OAJGK/zr1kwlOM0uNQnQMSAqvgQYtcbMVy4eNu
Eq4lrqQ7aqrhWglRtIjICaoJM9BemSs+3oDhMSscifGYcoz0h5sOEwBaf7XDDBQ2ZOEwuv/fV
K8HL9gysZERSuBpS42+4NKWV4c9E51VcvZ6t+CjoqSiHKSFUklhexi5GNkaK046sO9FoPFt3R
3vUQjN+fruzwIIOBE1w3uu+PeCts6md9iZBaTtlULY9Xixr1oo+HBYKLbU43ueN9qnzaZrVpR
mJ6o3N05+fw1zwaWrecAS1S5enzB8YeqOUuNsXMVouDSh2CYR5IqpW/+PyEdf8Zh+J5Angqka
6wVaakuGNUUc9HsyYh4+9S3cOp+Z8qZ/BYw1mcXuoEQDi+uAN7dyUzV7x6PMdXtqbNKs/eFNw
FyztgTobYOd/yGlRxqkJH0kHxGaCATV5C+MrhyQTXwQPS5MD+dt3J+gS/IAHo8nV96Hl26kNh
+mrdvMmmzpf/8IbnV3B3icP/bFhG48zzb+V20AZfK5yUO3ckuxnOLoteXGvDCETIUZEMRLCh7
UrJGN2OHkk0E3nPhMczYhTFZcJ9oL3rF4KjRK2csQy0A8l0mq7uzLIXaBk3+3nP5mdk1gy6kz
czrei243M504l+8VmMg+dR7GWd/usoWQ/5wNCD29IONQRQ0AjxolNU9nWJ3Fm1xlmQ8IHjtg5
R1fODRajZ/2CLP15nt4AgBzku5Eak9WPCRuN4rVahxczqzRSrpJcFk/IGPVpNHDmDGIF64AAU
QMo6Bj+SjhsvUndiF57OI89fugHTZnORcPLqyvdEtvH319zes1N3rBn2z70vrEK4xOv+TWFz6
63qDdPPWL8CPTcKcnh5NSu9kzKVUV5pp8zuZie5cpvRfLvOPz2UT0TZpBqJ80QqRvRhymWQ/l
/1PAk2WNHTHKGg=
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: <Yc7y2uhvqI9BTxhv@hermes.hilbert.loc>
X-Mailman-Original-References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<mailman.75.1640908231.3079.python-list@python.org>
<661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
 by: Karsten Hilbert - Fri, 31 Dec 2021 12:08 UTC

Am Thu, Dec 30, 2021 at 03:57:25PM -0800 schrieb hongy...@gmail.com:

> > > Then what cases/scenarios can demonstrate the beauty of recursion?
> > >
> > Walking a tree.
>
> There are many type of trees. Do you mean all of them?

Palm trees don't lend themselves to recursion all that much.

Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B

RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigross@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: RE: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed
Date: Sat, 1 Jan 2022 00:18:16 -0500
Lines: 45
Message-ID: <mailman.79.1641014301.3079.python-list@python.org>
References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<mailman.75.1640908231.3079.python-list@python.org>
<661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
<Yc7y2uhvqI9BTxhv@hermes.hilbert.loc>
<055a01d7fece$fbb721c0$f3256540$@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 3VF3Q80UMms0gOuSXNInZwNyUsyGME30dL44BKRrzzdg==
Return-Path: <avigross@verizon.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=verizon.net header.i=@verizon.net header.b=OuHIL3bJ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '31,': 0.05; 'fairly':
0.05; 'random': 0.05; 'flags': 0.09; 'gpg': 0.09; 'karsten': 0.09;
'parse': 0.09; 'schrieb': 0.09; 'subject:not': 0.09; 'steps':
0.11; 'questions.': 0.14; 'url:mailman': 0.15; '-0800': 0.16;
'1713': 0.16; '7:09': 0.16; 'constantly': 0.16; 'hilbert': 0.16;
'indeed': 0.16; 'instance': 0.16; 'iterative': 0.16; 'node': 0.16;
'received:(vzm hermes smtp server)': 0.16; 'recursion': 0.16;
'structures': 0.16; 'them?': 0.16; 'trees.': 0.16; 'probably':
0.17; 'thu,': 0.19; 'to:addr:python-list': 0.20; 'languages':
0.22; 'idea': 0.24; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32':
0.25; 'url-ip:188.166.95/24': 0.25; 'discussion': 0.25;
'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25; 'anyone': 0.25;
'classes': 0.26; 'friday,': 0.26; 'sense': 0.28; 'computer': 0.29;
'dec': 0.31; 'url-ip:188/8': 0.31; 'collected': 0.32; 'python-
list': 0.32; 'replies': 0.32; 'mark': 0.32; 'but': 0.32; 'there':
0.33; 'mean': 0.34; 'header:In-Reply-To:1': 0.34; 'subject:that':
0.35; 'people': 0.36; 'special': 0.37; 'subject:from': 0.37;
'using': 0.37; 'though': 0.37; 'way': 0.38; 'single': 0.39;
'much.': 0.39; 'should': 0.40; 'forum': 0.60; 'including': 0.60;
'best': 0.61; 'search': 0.61; 'method': 0.61; 'from:': 0.62;
'to:': 0.62; 'skip:b 10': 0.63; 're:': 0.64; 'received:74.6.135':
0.64; 'decision': 0.68; 'received:74.6.135.40': 0.69;
'received:sonic302-1.consmr.mail.bf2.yahoo.com': 0.69; '2021':
0.71; 'tools': 0.74; 'sent:': 0.78; 'catching': 0.84; 'entered':
0.84; 'inherit': 0.84; 'beauty': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1641014298; bh=MBn8I6/DAMxy0Ws1pTsNm/YE9q/8fZPEL/Z3HDuML2s=;
h=From:To:References:In-Reply-To:Subject:Date:From:Subject:Reply-To;
b=OuHIL3bJY95BC5VQJ4zj24T+sEkerdB2JlA+7iyxLI0xq2ZYp8qxgJ1vA1qcL9VuXVfFlMQobX+F+/D19zjA5wdoIf+o+OQ/t+xL0AOIAGeEwP7KF6XLbB4DoMw6GgE/dk+/ZzTkXgnCUhvVQ7regv0cExykY4WTtgdDlDn7D82KjAYA2UXkhZSQrfFbd68VmywxjCiXOTtFIwmB7PNIu+Ih3CO9SWp3Ipdo/6ytHR0ZecAvMT0bpxkxXU050XXIKfUDs/ZiorKN0MfpZDSErM064Dau8pIM9WFv2SsKe+uTny86wcC4MsSv02rBExEVGiTEGpynNSoAAXQ8FQrkag==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1641014298; bh=pdYd03MyP/LtwZHZk3lx1oolOxlgxqjIjTYNdhjG6xt=;
h=X-Sonic-MF:From:To:Subject:Date:From:Subject;
b=jyI85aj4XZCe+Hnl50nDywoCswP1PGsRm3VLyRTnUaavC2r8a4PTD/dSY4V35mcZaFUaR8kvwlpQl0bp9e7I8v/o/c/3a0axN+tQeG42PV+MnTFjThXo9njy9KXi1RiQxYyA5KS7dREnEDA+JGvyaPU1ZDnyyLopgnE4OoGydUVOpVud+NcJXOPjnD76I35RyPLt1E7ruGIH09R/yh1YxkOlER1fgzcBHxsaHlkj/A+bCqzpGOs6TizIk6q0ZcZ2Gd+2hMAJYzRowb5XeLKf3+PXHiuohMn0iguXE1DUyAFyWbiBg50PR0CgG1eQ3F8glJohLammK3fWtQGD3gGhDA==
X-YMail-OSG: uKeNwd0VM1mfk47cODV1O7LRR9US.cPFL.8tx4mygzfcz2PkkxdIwRe80Y36hIx
3_4I9u0HqJYMGUBveQmhMgMpxuVlOiK0d94grEgJoRyCkd2JbboR.uUGl7Ydvnz0zkmxvLqnWKJm
.lm1A14ZhyLzGbRyhmEBvK1Fr8qx4RwxlqZBjmEHp3Eat0kO5LqLWTVyMBwvE75V8r0HkbDo.xYZ
Vb2oC7F6n8xMfsiOrQTMFjS66pp7jraxKL65ZzVBUI2XXTExZUBDtv5Z8gnoAr2d10FcoWundoJq
ZLecb2l3F0YVUlmFW9caxWWIDy9F3eNvFcDDq8Ej6OHzpSONR5.598BpGjR45n31nJmIrVvNiZ18
GL01wAMdWdnoWye15jFqwTG4NVrGtksoRiDoYNuM0ZLv6smNQP051Z1Oon_xbMzXDNqV42sK7__J
cPKfBWSEF0S.bc6Awl1TTyC_mLwgDs5vKNbUy7TB1Pgr6.s22BUWcc1Mxzif9mhhMTwGFSo1n.eT
3vTHbg9zeCTyPo1FANx9C_nlX0UHpkQuSWSNQOC9BPFXhdQlj8xxx_e5YuobjvdazdCiatgx1XO0
Vr97ba_o1_sq3yeyexSnLlLPdzMhXyMyxOBDqlRMWg_bJSIhcpR4zCc8L.Ficr1dAAX56rTCrdrb
kE3QB3EtYI0dGRwH_Hau8ZNHFMvHzlgFlpJCUw6qPi2c5a40Q9uX1_.Xo760TyRff1NFcYN50TAm
ZhuLzNGmmr7awMzx73PkYlNXdHDRJtkdNZzJCnk82VbbqQneB2nFc37ENpPX2OIkRoBLjvduvSh5
zoAh.veeC8k0nMeJbc9JGLLif.Ok.71xmZP5I97vAlSY15j3c69jyfVR.2w5E8uIJiQz3lBcH0UQ
Ub5yA4midZBZaxrZtJYITEc_ascVptEs7lKYLgbt.bY5CWiZ58lg7zcmn4liYbnRryxC9N.UYgTO
k2JLTkHyYj1Mo.llHHmQKRyyViRxRc8v.x7eF2RE8WWC0sh.IBnDltb774hYkAZ03kJgWwDVG1K8
KKcQOtjs2vU.nsB3ZtMx1H6Nnx.3uS3d0PJ3oAcssVtTpYZINYp4O35J8JM23.apLUg7ucHMSWdw
Z9Ab6T.KRS84g_kGSZV2D_H2LZZYCoRWkYKoz.XLiuKlo5PKMqeCs.8H5Dcf.Z7JWCvDEzDkdvO7
kcyUr31X8yf5GQ0Q08kn589Xvo8DzpvoKYa30BV9ARBIWJzUdVWGt25P.6t6hxFUNMH7meY.qp5j
oLIuu_Z1hNaCUxHSQk_R0LCejCkMVZ.hUyVm95x59p46z.psze92cCkwbaMx1ttJo0jT89brLFUB
uuC7iOTMcrwuuBarAnIq8fQCVIItLIitSp2SpYlahaSq7mS2u2PxDqnEdPBlNJa7HryPA87xvC_H
CwCFgSeDFiPx93NgL5ECOmIhWbRu9a058v8dBs4WyIShLz_O6m_xIqIJq5VbRXwKQQfFiww.biVW
vdekT1Te6Ux3fBVlCodCiF7sMgqZ4d9nRWfvhP12OYdZUW6Pk27N0jpFSUhNQJJmX1njeV_ZhHpI
zunJuyVN8E.GFQvHt91O6yMQ09Nth1YI7C1Uox1LtFAYflct900jtzxM8RXleZ5TApdw2.8sMvlc
JW8PUH6Qz89UXGwEBXuFLnwjkhfgT58ktEe6wU.piM_RwnDXIhG999.xrrguZD3S_cRmnzN9CvCT
WCToV3w01mx747WG_nAlYXyj5FS5XeXCrbC1GG6ZLd_HkMbM10L3eLlZKqOPQjp2xEErdEUEXbjG
ufEzzBZwjlSgoOiWnfjkwdxpc3jLgcbgeKa.XZrQyd7c8lvf.Jd2H.owO96rG6uR1Vhv5IMMF_Rp
Wdhx5SK4NNhgTFxVHHTgPgkDNlGb5H4vy66P3iSKrLOehpRs4iJ_S.WfzzJet0FM7Z9ytDZk_5ma
22zaWNQ_kRlksYFIfy7NDZN_W4sWDsrcjEK9SYXrA6eLl7ivvhCvNxG0T8KYf.gW0XI_2MBEelPW
z2OUTonXVptp6Hn5fixEwUSneDVfvyLDQZ0A.coWhognr4Y9wDASBXa3oeXzVnnqXrUIrdbYn.Kp
qoRKeY4gnr.OikiubwDM6b40itCieZs.wo6VgWTXEBlMMmoq0cmgMuCdBUXOgVmWCRHBj74K8iBg
z0roYrWoluUSch30febSbBnSjaWpMOLtLaxrmltcfdwZxf69MCO2OyQyQ1.JrVVcyN3z5lDGQPQV
8FoKqNBXsLT0-
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <Yc7y2uhvqI9BTxhv@hermes.hilbert.loc>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQJJLGXRjr/qUuE4Z8QAhSCkRxWHrgMTLMBFAs9lEjIB+f9UigKCLfGRAkbxZ80Bdc/U/gHeSUSWAUzbl6QBZbDfNQMKkqK+qr2LwRA=
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: <055a01d7fece$fbb721c0$f3256540$@verizon.net>
X-Mailman-Original-References: <CAPTjJmq22Xez9SuNys971C_xmX+xE70HfxOSX_AVqVWeuoNOkA@mail.gmail.com>
<d7cd019a-9a61-43e5-a3aa-8256a528580bn@googlegroups.com>
<mailman.70.1640877797.3079.python-list@python.org>
<CAPTjJmodUF0_pZjpSVPa6RtuYuCUVOcJu69nY-yqU8etqT2v2g@mail.gmail.com>
<170b346e-2923-4519-b337-1db7b1978684n@googlegroups.com>
<mailman.73.1640905447.3079.python-list@python.org>
<2218d5fc-8862-9525-4c75-c2225e6247ac@mrabarnett.plus.com>
<df8487f1-2a28-48a1-9c9d-dafae37abf26n@googlegroups.com>
<mailman.75.1640908231.3079.python-list@python.org>
<661ece76-fe30-49a9-85be-efc70d7dc395n@googlegroups.com>
<Yc7y2uhvqI9BTxhv@hermes.hilbert.loc>
 by: Avi Gross - Sat, 1 Jan 2022 05:18 UTC

I am sure some people have a sense of humor, but anyone on this forum who
actually does not have some idea of what various "tree" data structures are
in computer science, probably won't get any replies from me when asking such
questions.

But indeed there are things closer to classical trees that are traversed in
various ways including depth-first versus breadth first. Some have special
names like a parse tree or a decision tree and they can even be collected
into a random forest.

But fundamentally, the idea of using a recursion that at each node may take
multiple next steps by calling an instance of itself at the new node, is
fairly common, as are using it to search many kinds of data structures.

The discussion though suggests that no single idea about computer languages
need be used constantly and sometimes recursion is not the only method or
even the best method. You can design tree structures in ways that allow them
to be traversed in an iterative way such as having bi-directional links
along with flags that mark where you entered a node from or already visited.
Tools should be tools, not religions.

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Karsten Hilbert
Sent: Friday, December 31, 2021 7:09 AM
To: python-list@python.org
Subject: Re: builtins.TypeError: catching classes that do not inherit from
BaseException is not allowed

Am Thu, Dec 30, 2021 at 03:57:25PM -0800 schrieb hongy...@gmail.com:

> > > Then what cases/scenarios can demonstrate the beauty of recursion?
> > >
> > Walking a tree.
>
> There are many type of trees. Do you mean all of them?

Palm trees don't lend themselves to recursion all that much.

Karsten
--
GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B
--
https://mail.python.org/mailman/listinfo/python-list


devel / comp.lang.python / RE: builtins.TypeError: catching classes that do not inherit from BaseException is not allowed

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor