Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.python / Context without manager

SubjectAuthor
* Context without managerPiergiorgio Sartor
+* Context without managerDieter Maurer
|`* Context without managerPiergiorgio Sartor
| +* Context without managerStefan Ram
| |`* Context without managerStefan Ram
| | `* Context without managerGreg Ewing
| |  `- Context without managerStefan Ram
| `- Context without managerDavid Raymond
+- Context without managerGrant Edwards
`* Context without managerGrant Edwards
 `- Context without managerGreg Ewing

1
Context without manager

<ep4a3k-0g5.ln1@lazy.lzy>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24776&group=comp.lang.python#24776

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de (Piergiorgio Sartor)
<piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de>
Newsgroups: comp.lang.python
Subject: Context without manager
Date: Sat, 25 Nov 2023 22:15:58 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <ep4a3k-0g5.ln1@lazy.lzy>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="936d932117e1ad3611592bd2fe3d921d";
logging-data="3099332"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/guu2utxvaDtt6ffrk0fif"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dW4PRikkHR9SaZhAdmezjgJAA6k=
Content-Language: it, en-GB
 by: Piergiorgio Sartor - Sat, 25 Nov 2023 21:15 UTC

Hi all,

I apologize in advance for the "foggy"
question, but I've myself unclear ideas.

Anyway...

Python has "context manager".
For example, the "open()" class can be
simply used as follow:

with open(...) as fp:
fp.do_something()

On the other hand, it is also possible to do:

fp = open()
fp.do_something()
fp.close()

Now, if we want to use "open()" in a class,
it would be possible to apply the second
variant, with "self.fp = open()" in "__init__(...)",
"self.fp.close()" maybe in "__del__(...)" and having
few methods doing this and that with the "self.fp".

Apparently, the "with" context manager is not usable
in classes, at least not with __init__() & co.

It seems there are classes ("gradio.Blocks()", for
example) which are *only* usable with context manager.

I found more...

One way to do the same as in "open()" is:

def __init__(...):
fp = open(...)
fp.__enter__()
....
def __del__(...):
fp.__exit__()
fp.close()

This works, but it seems quite ugly.
I could not find any other way, in case the
class do only support context manager.

Question: is there any other way to use a
context manager only object within a class,
with methods accessing the object?

Or any other solution to the same situation?

Thanks a lot in advance.

P.S.: currently gmail posts are deleted, due
to excessive spam, so I'll not see any reply
coming from this family of addresses.

bye,

--

piergiorgio

Re: Context without manager

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24782&group=comp.lang.python#24782

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: dieter@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Sun, 26 Nov 2023 18:50:38 +0100
Lines: 20
Message-ID: <mailman.296.1701022408.3828.python-list@python.org>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de cPjv3/WzS3eH6PUhrsQ/9gM/OhmFBIIRH3H6cS8MPO4g==
Cancel-Lock: sha1:HjDFTSHwcTcn99XaMlPkKglyFig= sha256:OT85MuDaexKORQbf0P2eGUI2ZFP/1wuyKDjn4pEY3Ns=
Return-Path: <dieter@handshake.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.070
X-Spam-Evidence: '*H*': 0.89; '*S*': 0.03; 'pfxlen:0': 0.03; '(e.g.':
0.05; 'subject:without': 0.07; 'cc:addr:python-list': 0.09;
'instances': 0.09; 'cc:no real name:2**0': 0.14; 'classes,': 0.16;
'usable': 0.16; 'cc:addr:python.org': 0.20; 'received:de': 0.23;
'cc:2**0': 0.25; 'classes': 0.26; 'perform': 0.26; 'context':
0.32; 'header:In-Reply-To:1': 0.34; 'class': 0.37; 'file': 0.38;
'least': 0.39; 'use': 0.39; 'wrote': 0.39; 'method': 0.61; 'down':
0.64; 'body': 0.67; 'header:Received:6': 0.67; 'operations': 0.68;
'manager': 0.68; 'received:88': 0.84; 'statement.': 0.84;
'subject:manager': 0.84; 'manager.': 0.93
In-Reply-To: <ep4a3k-0g5.ln1@lazy.lzy>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
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: <25955.34158.142219.335334@ixdm.fritz.box>
X-Mailman-Original-References: <ep4a3k-0g5.ln1@lazy.lzy>
 by: Dieter Maurer - Sun, 26 Nov 2023 17:50 UTC

Piergiorgio Sartor wrote at 2023-11-25 22:15 +0100:
> ...
>Apparently, the "with" context manager is not usable
>in classes, at least not with __init__() & co.

You can use `with` in classes -- with any context manager.
However, you would usually not use `with` with a file you have opened
in `__init__`.

If a class defines `__enter__` and `__exit__` (i.e.
the "cntext manager protocol"), then its instances
can be used with the `with` statement.

The important use case for a context manager is the
situation:
set up a context (--> method `__enter__`)
perform some operations in this context (--> body of `with` statement)
tear down the context (--> method `__exit__`).
If you do not have this case (e.g. usually if you open the file
in a class's `__init__`), you do not use a context manager.

Re: Context without manager

<i4hc3k-uqr.ln1@lazy.lzy>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24783&group=comp.lang.python#24783

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de (Piergiorgio Sartor)
<piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de>
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Sun, 26 Nov 2023 19:58:58 +0100
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <i4hc3k-uqr.ln1@lazy.lzy>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<mailman.296.1701022408.3828.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="aade65e6874b8d864d6d111c658ecfbd";
logging-data="3551831"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZCJo+h/UNa+Uro160Yxtt"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CrMN8LBarl9wmXkrcfeldCJpsBM=
Content-Language: it, en-GB
In-Reply-To: <mailman.296.1701022408.3828.python-list@python.org>
 by: Piergiorgio Sartor - Sun, 26 Nov 2023 18:58 UTC

On 26/11/2023 18.50, Dieter Maurer wrote:
> Piergiorgio Sartor wrote at 2023-11-25 22:15 +0100:
>> ...
>> Apparently, the "with" context manager is not usable
>> in classes, at least not with __init__() & co.
>
> You can use `with` in classes -- with any context manager.
> However, you would usually not use `with` with a file you have opened
> in `__init__`.
>
> If a class defines `__enter__` and `__exit__` (i.e.
> the "cntext manager protocol"), then its instances
> can be used with the `with` statement.
>
> The important use case for a context manager is the
> situation:
> set up a context (--> method `__enter__`)
> perform some operations in this context (--> body of `with` statement)
> tear down the context (--> method `__exit__`).
> If you do not have this case (e.g. usually if you open the file
> in a class's `__init__`), you do not use a context manager.

Very clear, but what if the class is *not* "open()",
but something else _requiring_ using "with"?
How to do this in a "__init__()" of a class?

In other words, what if "open()" could *only* be used
with "with" and not just by assigning "fp = open()"?

The problem is I've some SDK of some device which
provides context manager *only* classes.

I *cannot* do:

device = device_open(...)
device.do_something()
device.close()

I *must* do:

with device_open() as device:
device.do_something()

Nevertheless, I _need_ to have a class
where the device is opened in the __init__()
and used in some methods.

Any ideas?

bye,

--

piergiorgio

Re: Context without manager

<contraction-20231126201357@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24786&group=comp.lang.python#24786

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: 26 Nov 2023 19:15:53 GMT
Organization: Stefan Ram
Lines: 47
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <contraction-20231126201357@ram.dialup.fu-berlin.de>
References: <ep4a3k-0g5.ln1@lazy.lzy> <25955.34158.142219.335334@ixdm.fritz.box> <mailman.296.1701022408.3828.python-list@python.org> <i4hc3k-uqr.ln1@lazy.lzy>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de xcxV7/FhxzWirOpZfKd/ew5KfieSyIzQEzacQUXSMJ63c/
Cancel-Lock: sha1:efbZM+xYVRHUpcssWKHN7s4pr/E= sha256:g+YNoaRD1L5zKB6B16K29R9OWAuErINY7B4vFopMkHU=
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Sun, 26 Nov 2023 19:15 UTC

Piergiorgio Sartor <piergiorgio.sartor.this.should.not.be.used@nexgo.REMOVETHIS.de> writes:
>The problem is I've some SDK of some device which
>provides context manager *only* classes.

Everybody please excuse my being off topic. But it really
make is hard for me to read messages when contractions are
used in a way that seems wrong to me. I noticed this now for
the third time in a post by Piergiorgio.

I (not being a native speaker myself) think, when "have" is
the main verb, it is not contracted. It's contracted when
it's an auxiliary verb. So:

I've seen this before.
I've got another an.

, but (note that no other verb follows "have" directly):

I have been there.
I have all of them.

I wrote all of the above just by my own judgement, but now let
me try to find something in the Web so support this: Web:

|As far as I'm aware, verbs are usually only contracted when they are:
|auxiliary, e.g. 'are' in they're leaving, and
|unstressed (they can be attached to a stressed word but remain
| unstressed, themselves), and
|informal/casual (or formal when quoted verbatim).
....
|in en-US, where they favour using 'have' as a main verb, which
|does not get contracted:
|"I have money"
....
quoted from the World-Wide Web.

The other two cases were:

>>>>I've myself unclear ideas

and

>>>>I'll not see any reply

.

Re: Context without manager

<makes-20231126210316@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24787&group=comp.lang.python#24787

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: 26 Nov 2023 20:03:55 GMT
Organization: Stefan Ram
Lines: 18
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <makes-20231126210316@ram.dialup.fu-berlin.de>
References: <ep4a3k-0g5.ln1@lazy.lzy> <25955.34158.142219.335334@ixdm.fritz.box> <mailman.296.1701022408.3828.python-list@python.org> <i4hc3k-uqr.ln1@lazy.lzy> <contraction-20231126201357@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de qRgKDY+XGAUOSZvuu5Yc2wd52jfjl+hh4KoF2QcssOpFHQ
Cancel-Lock: sha1:6AXg45FGuafYNVPnlW+tSw8MzG0= sha256:237Uo+BHB3kvMoAJfTJwsv1S0CzFHhetyt70s7TYwR0=
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Sun, 26 Nov 2023 20:03 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>Everybody please excuse my being off topic. But it really
>make is hard for me to read messages when contractions are

... makes it hard ...

>I've got another an.

I've got another one.

>, but (note that no other verb follows "have" directly):
>I have been there.
>I have all of them.

Above, "have" is followed by another verb in "have been",
so it should be eligible for a contraction there!

Re: Context without manager

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24796&group=comp.lang.python#24796

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b.edwards@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Sun, 26 Nov 2023 19:43:53 -0800 (PST)
Lines: 17
Message-ID: <mailman.307.1701056638.3828.python-list@python.org>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<65641079.050a0220.5914b.9566@mx.google.com>
X-Trace: news.uni-berlin.de 4RmlnFUchpr9mm9T5DtJ5AlszG88VHs7SPEwSqodeZWg==
Cancel-Lock: sha1:JsDZiH1bX1p31j/y8sjhtboeOGc= sha256:ukbsXTAUkpA/RYoRaXtZ/rU5J3qTsXwsWd/syGrbVgc=
Return-Path: <grant.b.edwards@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=nfgMfXHf;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'knows': 0.04; '(e.g.':
0.05; 'usage': 0.05; 'subject:without': 0.07; 'received:mail-
qk1-x72b.google.com': 0.09; 'that.': 0.15; 'dieter': 0.16;
'from:addr:grant.b.edwards': 0.16; 'from:name:grant edwards':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; 'manager,':
0.26; 'header:User-Agent:1': 0.30; 'context': 0.32; 'python-list':
0.32; 'but': 0.32; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'using': 0.37; 'class': 0.37; 'file':
0.38; 'use': 0.39; 'methods': 0.39; 'wrote': 0.39; 'wants': 0.40;
'subject:manager': 0.84; 'fool': 0.91; 'manager.': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1701056634; x=1701661434; darn=python.org;
h=to:user-agent:references:subject:from:date:message-id:from:to:cc
:subject:date:message-id:reply-to;
bh=lFL+0I+FZJM9yXWJ29WA3vcQ6pcTG43JNINLtpadbdY=;
b=nfgMfXHfz9iDHLzEqrCR5paSL4iAzd7dqGy5zZW2LS3yEY9I1EkV48MFU8E7RqFTPp
VjTYAK4tWEgq5X9X0DOGz3njZpYRVmeA5E8nq0dLmsi2GWFyTQMUhcuSQ/nNrOHyZLTr
q6SFCCt4wXZ+k56+PK+Zin95Qm+r7HLKdPLWBY5Ih2lqEH465l+jZDXQ1eMU3Su4mRZI
NvHQk5qdZlG8iIiwzQ4Bb91B60kB28AkxJBHqKrctXkyjTlglqaIB5lhnUX3i6qNrw3W
nZk9r5mRm2/etdpVe5K2w3N5HhCzHlHQTa5G9c4AjVBI2XwcRLT2Mxlm9e77JJDc+sY5
8RGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1701056634; x=1701661434;
h=to:user-agent:references:subject:from:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=lFL+0I+FZJM9yXWJ29WA3vcQ6pcTG43JNINLtpadbdY=;
b=iTAQM3HsbAig1ljBQhlJODMl2feUUT8p6InZMwM92am0lPTk4bM+CWLPfg5dMlkWwt
7PoDTA28hPKjDJUzWe5yU/9jS/h/ZSRKhLsYw6USeyGbxLkDc+BEwbL7ToIMrUBFuJF+
Oq3rHu1M1iQgIzt1kMXeGzjqdcKv/e1fHUviVZSg7LQxn7KSBNJpBjF4RQph4WzxWV4k
frXwumUq+xansOKgheoJO9/eD6bGy3SrMtX6+aUW5DwpcJr8O15DxCLBhXJOxXemZFYF
4/3M9RCH7pdiCGRKgujgXaKthNMZuguxAzBMLWpSSdZ7eWBgZTiaplI+RyvzUTkvJWsR
7M5w==
X-Gm-Message-State: AOJu0YwHvae5joC9pj5Yv67VLoOC39U9xAmwNA1WNiIiV/l26sTosCZR
CmpuKnn3Zq3Pqeke+jwZpTecq8i9wSc=
X-Google-Smtp-Source: AGHT+IHfOJX3twbQfJhqM+/sdVRh8pwr5zGtF5nG5C4zKHnVNrAsocVbq4gDpYx1dFO8XByqIVRSvQ==
X-Received: by 2002:a05:620a:8292:b0:77d:7974:1e8a with SMTP id
ox18-20020a05620a829200b0077d79741e8amr10448415qkn.70.1701056634520;
Sun, 26 Nov 2023 19:43:54 -0800 (PST)
User-Agent: slrn/1.0.3 (Linux)
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: <65641079.050a0220.5914b.9566@mx.google.com>
X-Mailman-Original-References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
 by: Grant Edwards - Mon, 27 Nov 2023 03:43 UTC

On 2023-11-26, Dieter Maurer via Python-list <python-list@python.org> wrote:

> If you do not have this case (e.g. usually if you open the file
> in a class's `__init__`), you do not use a context manager.

He knows that. The OP wrote that he wants to use <something> that can
_only_ be used by a context manager, but he wants that usage to be
spread over various methods of a class he's writing. So he's asking
how to fool that <something> into working when he's not using a
context manager.

--
Grnat

Re: Context without manager

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24797&group=comp.lang.python#24797

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b.edwards@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Sun, 26 Nov 2023 20:03:20 -0800 (PST)
Lines: 17
Message-ID: <mailman.308.1701057804.3828.python-list@python.org>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<65641079.050a0220.5914b.9566@mx.google.com>
<65641508.050a0220.15ec4.9beb@mx.google.com>
X-Trace: news.uni-berlin.de 98zfU+1bbFwlcOiNd0+/ZQFeuN1hMdFIgBI9DNc0XXZA==
Cancel-Lock: sha1:iQQXC8gK8nwseyltqRgiTg3Kv9E= sha256:OzLJhKk4gdiVlkSWwSyCp1kv/k3qyWdgCtt1z1E3B4s=
Return-Path: <grant.b.edwards@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=LVDGHn+t;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.011
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'knows': 0.04; '(e.g.':
0.05; 'usage': 0.05; 'subject:without': 0.07; 'that.': 0.15;
'dieter': 0.16; 'from:addr:grant.b.edwards': 0.16;
'from:name:grant edwards': 0.16; 'received:mail-
qk1-x730.google.com': 0.16; 'wrote:': 0.16; 'grant': 0.17;
'probably': 0.17; 'to:addr:python-list': 0.20; 'written': 0.22;
'manager,': 0.26; 'header:User-Agent:1': 0.30; 'context': 0.32;
'python-list': 0.32; 'but': 0.32; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'using': 0.37; 'class': 0.37; 'file':
0.38; 'use': 0.39; 'methods': 0.39; 'wrote': 0.39; 'wants': 0.40;
'should': 0.40; 'subject:manager': 0.84; '"how': 0.91; 'fool':
0.91; 'manager.': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1701057800; x=1701662600; darn=python.org;
h=to:user-agent:references:subject:from:date:message-id:from:to:cc
:subject:date:message-id:reply-to;
bh=AF6niAGClLzLNwkYZ7WyLA3H9K6IX4nhegdzdOcOzxU=;
b=LVDGHn+tm0dX26hjCO1KXF2c2tx+wYpteaiLTgWcm6tLFuJS7SSJGRgYko39sTSCQ+
UU19lCZ3/6iJ4TUlYeqP8JA4+Y7PlVSyi+hIgLT8b2KKnwI6LV6t4sCI6dCBMJqPiMiK
FPo/qGoKdIErRIfIWo0iNqGQyWC+mUXaHjszdRKFXSB5e0rOqeJ63rNXOB7wWSgaUKYZ
CAAKt3PfyPz2/Fobl4LlaEWIbyzpfXZHGzO08E/nBYmZFyn/gslDO75yK1LzDRhOZ853
Dko7lN53DDMqe4FLB56IwjnxAeyxJ98AW1MYl78wnRiNbHZ11HgdRZiKZH8fEXZ2+PE1
AGRw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1701057800; x=1701662600;
h=to:user-agent:references:subject:from:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=AF6niAGClLzLNwkYZ7WyLA3H9K6IX4nhegdzdOcOzxU=;
b=pqxDXWH5z2fH2DcVo4PirIA+chQUMHcwefd6TL7tgN0Gp2ZigJ6qRZcdet0BEO01+D
JJvQsSOl74wzJFNhz7zkb6N+2zmAPMp4WrlmphFxB7YOCet/Zn/9hCiHhHlfeU2DdkSs
64hwttQkuShXiAmFfZqoQR8tXM0i3Q+FOM8+XZXVIQKLyMA5EhRwsDRnatCIdi4m43nA
swJw7rsqpfsKgRWLgMsxXcENhMYE1cD3ke4OVQzT01twwenaH0pXqR144Ce5ZTXEQPOv
K7zYAJ8okZVwFSBMi3SsZ031wy+EdXzKDrHY/h9isTFi4pvZtDKKF0p/dKBvqoNm2Lta
mTsQ==
X-Gm-Message-State: AOJu0YxZMjvskKHGhZHLUk3Hqoy3H9AWe54PGh09aIbw6T72IbMJWRYm
/XS1rWXT29kszpMQcjIPKsdnE4mp6WQ=
X-Google-Smtp-Source: AGHT+IGpU7ArCJNN5mQgSUFvCZ4s6IiPTc9ASIh6WmQHpD8dlGN1kx4CbIHpG6Gl8qRDIZqqjhM1iA==
X-Received: by 2002:a05:620a:8b0a:b0:77d:72b8:cc32 with SMTP id
qw10-20020a05620a8b0a00b0077d72b8cc32mr9171554qkn.14.1701057800619;
Sun, 26 Nov 2023 20:03:20 -0800 (PST)
User-Agent: slrn/1.0.3 (Linux)
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: <65641508.050a0220.15ec4.9beb@mx.google.com>
X-Mailman-Original-References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<65641079.050a0220.5914b.9566@mx.google.com>
 by: Grant Edwards - Mon, 27 Nov 2023 04:03 UTC

On 2023-11-27, Grant Edwards via Python-list <python-list@python.org> wrote:
> On 2023-11-26, Dieter Maurer via Python-list <python-list@python.org> wrote:
>
>> If you do not have this case (e.g. usually if you open the file
>> in a class's `__init__`), you do not use a context manager.
>
> He knows that. The OP wrote that he wants to use <something> that can
> _only_ be used by a context manager, but he wants that usage to be
> spread over various methods of a class he's writing. So he's asking
> how to fool that <something> into working when he's not using a
> context manager.

I should probably have written "how to fool that <something> into
working when he's not using a 'with' statement"

--
Grant

Re: Context without manager

<ksirisFohgjU1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24798&group=comp.lang.python#24798

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Mon, 27 Nov 2023 19:34:04 +1300
Lines: 10
Message-ID: <ksirisFohgjU1@mid.individual.net>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<mailman.296.1701022408.3828.python-list@python.org>
<i4hc3k-uqr.ln1@lazy.lzy>
<contraction-20231126201357@ram.dialup.fu-berlin.de>
<makes-20231126210316@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net T+wKBF7Skv//RiSkgPwdegd67Kfv8HMPfJb7ME7Y0cyeSSMld4
Cancel-Lock: sha1:HXttYhWIJ+d522aHt7tnsPGUsqw= sha256:CsXzQEUVKblSH78TNx4AcW+JmTmvru99l85owYzGYd4=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <makes-20231126210316@ram.dialup.fu-berlin.de>
 by: Greg Ewing - Mon, 27 Nov 2023 06:34 UTC

On 27/11/23 9:03 am, Stefan Ram wrote:
> Above, "have" is followed by another verb in "have been",
> so it should be eligible for a contraction there!

Yes, "been" is the past participle of 'to be", so "I've been" is
fine.

--
Greg

Re: Context without manager

<ksis42Fooi2U1@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24799&group=comp.lang.python#24799

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: Mon, 27 Nov 2023 19:43:14 +1300
Lines: 22
Message-ID: <ksis42Fooi2U1@mid.individual.net>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<65641079.050a0220.5914b.9566@mx.google.com>
<65641508.050a0220.15ec4.9beb@mx.google.com>
<mailman.308.1701057804.3828.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net BwniLofXkthoSoDlrrwCCQ8SPvXynSZ9OfZV5E9vS1a/qgeamU
Cancel-Lock: sha1:86uVgK50SVbfW1qMjhDGdSyFUOE= sha256:cGu8e6J85PShtg3x4R1WPSU2dW7muyM9hfO/xfyaark=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.308.1701057804.3828.python-list@python.org>
 by: Greg Ewing - Mon, 27 Nov 2023 06:43 UTC

On 27/11/23 5:03 pm, Grant Edwards wrote:
> I should probably have written "how to fool that <something> into
> working when he's not using a 'with' statement"

It should be possible to run the context protocol yourself.
Something like (warning, untested):

class MyDeviceWrapper:

def __init__(self):
self.cm = device_open()
self.device = self.cm.__enter__()

# Other methods here for doing things with
# self.device

def close(self):
self.cm.__exit__(None, None, None)

--
Greg

Re: Context without manager

<English-20231127114238@ram.dialup.fu-berlin.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24801&group=comp.lang.python#24801

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.network!news.neodome.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Context without manager
Date: 27 Nov 2023 10:43:40 GMT
Organization: Stefan Ram
Lines: 13
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <English-20231127114238@ram.dialup.fu-berlin.de>
References: <ep4a3k-0g5.ln1@lazy.lzy> <25955.34158.142219.335334@ixdm.fritz.box> <mailman.296.1701022408.3828.python-list@python.org> <i4hc3k-uqr.ln1@lazy.lzy> <contraction-20231126201357@ram.dialup.fu-berlin.de> <makes-20231126210316@ram.dialup.fu-berlin.de> <ksirisFohgjU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de D8LagBYvFVTwoFM0Q46Yeg9diC5g/RlqAuLfMe4prAfIYJ
Cancel-Lock: sha1:USKCki/v79FMNBR3Bdfy5Dc86/0= sha256:lGMl5ZzDsIVXfjftc/vAjU7VXWLo7rs1e+N0O09OD2s=
X-Copyright: (C) Copyright 2023 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE-1901, en-US, it, fr-FR
 by: Stefan Ram - Mon, 27 Nov 2023 10:43 UTC

Greg Ewing <greg.ewing@canterbury.ac.nz> writes:
>On 27/11/23 9:03 am, Stefan Ram wrote:
>>Above, "have" is followed by another verb in "have been",
>>so it should be eligible for a contraction there!
>Yes, "been" is the past participle of 'to be", so "I've been" is
>fine.

In the meantime, I had asked about this topic in a newsgroup
dedicated to English and was told that my view would apply
to American English, but that more contractions were allowed
in British English (and earlier in American English).

RE: Context without manager

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

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=24807&group=comp.lang.python#24807

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: David.Raymond@tomtom.com (David Raymond)
Newsgroups: comp.lang.python
Subject: RE: Context without manager
Date: Mon, 27 Nov 2023 17:58:40 +0000
Lines: 23
Message-ID: <mailman.315.1701107923.3828.python-list@python.org>
References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<mailman.296.1701022408.3828.python-list@python.org>
<i4hc3k-uqr.ln1@lazy.lzy>
<DB7PR07MB39166B38A5B358B0CA8012D187BDA@DB7PR07MB3916.eurprd07.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de X8LMl0bfNQA1ADSG6w/sIwNY40Uf7gL7b5cYnzRwEUKQ==
Cancel-Lock: sha1:tfDWPur/VJIeEsTR6kLYBSp8M0c= sha256:gb98pNdyiXi3V+99Z2xDEQkNuDTm2Aaari+35rjDjnk=
Return-Path: <David.Raymond@tomtom.com>
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=tomtom.com header.i=@tomtom.com header.b=ql3YC5l0;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.065
X-Spam-Evidence: '*H*': 0.90; '*S*': 0.03; 'def': 0.04;
'subject:without': 0.07; 'import': 0.15; 'to:addr:python-list':
0.20; 'skip:_ 10': 0.22; 'to:name:python-list@python.org': 0.24;
'header:In-Reply-To:1': 0.34; 'class': 0.37; 'something': 0.40;
'charset:windows-1252': 0.60; 'look': 0.65; 'subject:manager':
0.84
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=SAZmcOD2cEdhTU59YmCwSgdYiHlqWFM4DcsiaZODFImWKhLnsoHMPerPqpHXZlEG09eP9J3ab2NF8q05/H1JEDl/KUc+if3ag/4oR5fb+xIwF5pZ+zCPNtq0ImYGZSMdE9k555zf4b0oCWE+ma+o2tLTUNm/FdmxfSdTvfqeWZWbXKNPJ3UQ46kW/1Gra1LepIojbvJxyGKWWgscvpHk2MNy4wj9C0TeLzjN2NzAlaiyWGavSzOYy/seg6DYJq2hZalaNEoVh/VAhUdDvOoWKj6efYOtnUBvNvufcq14wAT5SeBygQjWDZCdEMuPbStnPh+bvId5BWkXkkR2pt6YOw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=fceedRrNHIdwUw5OOj/WG5KxbKoSjq15Za47jureOQM=;
b=KH+KOWDU3dHqOQo1ah6wjKiF322FjtNOO4190ZM50iu82lOMSnQV/t63uuSaZ0YVERErlhnohgxVWut7S576yZc74oKBtQT2U7F/gjMxWTLnTHG/K3H9J4RZbJKbK3O7GMK0dU+7Is5951q8xokvksOobiBPWxIc2t0+Bj5TrVUR/YGmKwhrWbYs2KJJjnd5KsNPYMUW/KvPFRgz/nNFXTtqSUoiTRPTsBVdir4y7nZXxyzg3199gE1yejGbuig3W/oWqsCKFyNskwxG0zkLgI02Si/0e4OhX6f6Q8Z1NT9LhV4LgBZZJMyX38EDsfjRo72RdTrth/q+CTS2lrBapw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=tomtom.com; dmarc=pass action=none header.from=tomtom.com;
dkim=pass header.d=tomtom.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tomtom.com;
s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=fceedRrNHIdwUw5OOj/WG5KxbKoSjq15Za47jureOQM=;
b=ql3YC5l0bnR/ZD6b+OWhkmIlZyNYCJSyiz1reD4cpaXNFi23GqT9m5bOAIwXlHKM1gZo/bxaGG+352brCteQ7Ilutj/qzJrJ18NdIwthniLBAS8X3SL+IKqmxb+cKSzLQocmY050GhPkW5efDkpnkWDM8In5cAbPNt6nQ3hWrOU=
Thread-Topic: Context without manager
Thread-Index: AQHaIFD4peaCF3gq4EKi6QZUXISBJbCM4X8AgAGKFRyAAAhDgA==
In-Reply-To: <i4hc3k-uqr.ln1@lazy.lzy>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=tomtom.com;
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: DB7PR07MB3916:EE_|AS1PR07MB8456:EE_
x-ms-office365-filtering-correlation-id: df70a131-745c-439a-1628-08dbef727d21
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: 5+YsNaLIjayPVg3C/KwSZ1fl1EkNCuxTyCPHZYGSyE9tuJmWSGf14lBpxSR6f5amrSzAx1ILmhHCAQhypFn1fdvw2HyQlp39JFxVPQi311eQTWC/uG+0uW7AbYBxqchST1ATA3cF0dZbVBY4xbxDC0H5IZ0+sv3yflp3mqvOHymzZkYpQA5svcwgPKCg+SQjLx3Hv7McaG/ZPgx2GibIbt1ikQGoLhBmGiZjNAdF2RLiiyNRjMsV7fQUG5BWNAsBs8GLHrrd/JYhREpTg32yvEYek/6QLBoQbXLYh95JWurjpfChnezuuH4ILm8oiDsAWAUw9Q8lIFrTCyonMoPlYhH+T9HHetNzVI5P4NbnYoTEZ5sSeRutR5QXplbXpE76cA3pQwzO7HW8qipWi34UldNIsG5ET7yyAhw1esrFjHViL92Q2V1OdgsNJcPV3usHtQ8Srmoyn1q2ox+KKu5kgIP/nodyncRVzvISigtuECsWu+Il0UgGlpbC83sUah23146kuWb2SHSdDfEGz5iLd6JEPVVm56fEadwYwkWCk8ROzG2qtHgwmPMk7JpwiR8zRj5CNY/oPqiysUePAQXFDKQMYEknK7EV7R7/1rfmAHxZhcO2fWuPWZAKWRedbhucD6wq6Yph8k6VJklYb200nrJtu+R8hpE6aDAMLrOyLzM=
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:DB7PR07MB3916.eurprd07.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230031)(39860400002)(136003)(366004)(346002)(376002)(396003)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(5660300002)(4744005)(2906002)(7116003)(8936002)(52536014)(8676002)(76116006)(41300700001)(64756008)(66446008)(316002)(6916009)(66946007)(66556008)(66476007)(55016003)(26005)(71200400001)(478600001)(7696005)(9686003)(6506007)(38100700002)(83380400001)(3480700007)(122000001)(38070700009)(33656002)(86362001);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: ZxVrxbjXa7ad+mFZ0mZxBBbBEcEuiQ7+X2AOvKr6lxem9OUFtZuHnIFU
S2vaL3Ei6A/2b6U8SF+thZWH4954fsknMwgI14/iiCad47FVsv6Cqk3i
p9kbksncOR7uLpA9napzIhoj08E2uYaYof5iVwQZu2byh7fXOVfaJ50n
ZggWgEwBxqPoj8yU+BkmUsyrvnpWMVUbcRvgRFqK+EVCuQJqZ2xR1EDr
QvTVv+SdfIGdpRr/31si+5jIi/3DPsPcMFnt5bmINimY3c+4dGyNy5tX
Uuj9nfs/PenLK0GA+w97VSTUTOVL2CWxOR01av2JaOfA60SprN3NOVQH
txhZXvRFKS+lgBvonRdSge1TXnlEFNrmKhYfDp5R/+aV6oXRhigpB+Yv
RVBa+WDmm8Wl1F+PjmvvhLGXjyk8DkXbn3FOxJjA/D/wP2v/yHwzPqZq
KZvvks+WGGQhs2E/lypMqfHxkBEcT+PMBlw85YGssSMX/V6o2/oPIbCD
kDG20esc9WzOL5r+vrcekxKNk3PUREvxMjqmQsgLdUDCSvVEXucXqLUh
tfd4HG5kKUz4ZCfgrjg4jlENM0rYzuskeOUpPltyj3w2olVraUv1bRZB
/rg+RW7VXs22Jh67bGi7+FT1ujWT9vOVtHs6iaTG0sVAn8sW5zt6huPS
fAhy1H+NL2JfCve5ui4OUL7XzJmueghI3HOohZfaAwuSxMIcqqZUoydS
x+2/IDgs9OcwJDTJr+BgyPHzpUl0aauudelH2NF60KKDDtpbldJK5Vwp
LcepYt+bR8Lpex14Ilis1m3M+qp6mz7W2IJrIdeV75v2WUWCl0uMc/GU
7Lwq7GubOOpyNBCJ5XgNQhI2jEFY2YPYqW8GSkDYSaEFa340dATGvUST
ZWVQhaf9hMrMgU/NIriTY4rdc1+dXQ6/gW5EAItPse8wbgXeYauwDhoR
pbVmDR8nu1HgL4rFBOjw9oyXRvmvUR++97g4NH21pyaQxMJZq1OpZTuA
AWJwfZqNqOaxvt/PKtd4XYwgsRjtV9rAudF9M7LlYOjieUQA386/9N/O
/YPUD1kZqxm6xh0z64Y0B/E8Bq0XYiAw4k8nifEkvdAe5wFM4sRp4i7l
jDt9tOK+yOgFvSNQW6qG/xvpUGCOulhmQRQEAV4Rlq5G0/A6DrByiNTu
U7r8NnidlFIqgYsl+/v2fzaznbgzmWIj8edDGygqWl33n/ywzSfZsEoc
1pm5xMxskQx24SSVAm9RwtTJ8cIB6WsQ+SzKXFBdI/zXoFE6y6qGLQok
O7CaZNirHxvDx5KVkG83oU3ULTW23zs3vz1oq9wPQHZOLs7/9X9Z3Fk9
qv71QZkCg2/8NCESHkq4w61eo2UfnLUfCgwJg71rpuemqYEDoRBf12M6
sCjdMKFEAhmsDbr3GfeIx3psrvA2W2QLVwXe+OzjsTtxFPoiIBfBUI/D
Kl1FrrxSqzRHiNvsKUYfsWMdYN4DyHv514rf3cG1d/PJ8/HVcxNiEacB
HA21d/Z3NDBFBMvjh4KcdSlq22WU7e+R8wYRKDJLDi4bf1wJaMNBwKQc
UVca4r44USxyeFUUv+bRP21N84RcQoLO
X-OriginatorOrg: tomtom.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: DB7PR07MB3916.eurprd07.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: df70a131-745c-439a-1628-08dbef727d21
X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Nov 2023 17:58:40.7569 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 374f8026-7b54-4a3a-b87d-328fa26ec10d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: 6rc/yxKHTZ+BZ3cQpvl22fpl+f4+qhQJunAJEqi3dwMpavkLv0IcTtDRjH5MpUPgoq9k0USxKYFBTxH6+RCWNFhE4JpoCj0+7i5/WljV5qo=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR07MB8456
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: <DB7PR07MB39166B38A5B358B0CA8012D187BDA@DB7PR07MB3916.eurprd07.prod.outlook.com>
X-Mailman-Original-References: <ep4a3k-0g5.ln1@lazy.lzy>
<25955.34158.142219.335334@ixdm.fritz.box>
<mailman.296.1701022408.3828.python-list@python.org>
<i4hc3k-uqr.ln1@lazy.lzy>
 by: David Raymond - Mon, 27 Nov 2023 17:58 UTC

> I *must* do:
>
> with device_open() as device:
> device.do_something()
>
> Nevertheless, I _need_ to have a class
> where the device is opened in the __init__()
> and used in some methods.
>
> Any ideas?

Perhaps take a look at contextlib.ExitStack and see if you can do something with it.

(Below is not tested)

import contextlib
class myClass:
def __init__(self):
self._exitStack = contextlib.ExitStack()
device = self._exitStack.enter_context(device_open(...))
def __del__(self):
self._exitStack.close()


devel / comp.lang.python / Context without manager

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor