Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will lose your present job and have to become a door to door mayonnaise salesman.


comp / comp.lang.python / Re: Best use of "open" context manager

SubjectAuthor
o Re: Best use of "open" context manager2QdxY4RzWzUUiLuE

1
Subject: Re: Best use of "open" context manager
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Date: Sat, 6 Jul 2024 11:09 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Best use of "open" context manager
Date: Sat, 6 Jul 2024 07:09:45 -0400
Lines: 13
Message-ID: <mailman.4.1720265784.2981.python-list@python.org>
References: <954c4ca8-cf37-4482-a1be-46d39cb503f9@btinternet.com>
<Zokl-STBBSgf3xJE@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de u9DQFLYaMVRBhfbljfcjMQJKdl1pGFBsu/pIsf+UvexA==
Cancel-Lock: sha1:9yvPOYT2kTSUeiA5y+QwOpn0YVo= sha256:cQaqvh8TpTEPufBxluedKW+vCcdflRDuI6aiO2MtSrE=
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.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=potatochowder.com header.i=@potatochowder.com
header.b=eq946TFQ; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.008
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'files)': 0.07; 'attempts':
0.09; 'dan': 0.09; 'received:78': 0.09;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'pythonic': 0.16; 'received:136.243': 0.16; 'received:71':
0.16; 'received:78.46': 0.16; 'received:www458.your-server.de':
0.16; 'received:your-server.de': 0.16; 'wrote:': 0.16; 'problem':
0.16; 'to:addr:python-list': 0.20; "i've": 0.22; 'received:de':
0.23; 'library': 0.26; 'python-list': 0.32; 'received:136': 0.32;
'but': 0.32; 'there': 0.33; 'header:In-Reply-To:1': 0.34; 'file':
0.38; 'least': 0.39; 'use': 0.39; 'full': 0.64; 'your': 0.64;
'rob': 0.84; 'subject:manager': 0.84; 'subject:open': 0.84
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=potatochowder.com; s=default2305; h=In-Reply-To:Content-Type:MIME-Version:
References:Message-ID:Subject:To:From:Date:Sender:Reply-To:Cc:
Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:
Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=tEVFGxj2JfKUIaT3Be0Jh5B4iPy7Oy/df2nHpIJB/1A=; b=eq946TFQR/GIz4l8YFnSog5cyo
yA3kvitq/3NnsyXFVjS+RuPm/WjSGTT9WDdw369beDWViiR3+YJ9dW5EgKDQ9x4CVeNYXKsAetIp+
4HfwlZnYD3Dojhrp8CzT02gOAygy4WdxxRZ1EHVMZrKJnvQy9r4VUZfMsIN0auhL0hJja887YuQcu
y3aTd8WPVhejZr7EpJiImhlahUstJfTFchCW6zEooC1gUNUCgRyQ+JIRtDgunVMC0t/KNfsbpv03b
t1kFnfGNStuh6xMpIuRKaF4Jgt56dZWqbP/opFdWcoNvwHYhjG7cShEFKlCEogK0sg2SA5WSZBjJ7
bW+1F4dA==;
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <954c4ca8-cf37-4482-a1be-46d39cb503f9@btinternet.com>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.10/27328/Sat Jul 6 10:34:31 2024)
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: <Zokl-STBBSgf3xJE@anomaly>
X-Mailman-Original-References: <954c4ca8-cf37-4482-a1be-46d39cb503f9@btinternet.com>
View all headers

On 2024-07-06 at 11:49:06 +0100,
Rob Cliffe via Python-list <python-list@python.org> wrote:

> Is there a better / more Pythonic solution?

https://docs.python.org/3/library/fileinput.html

At least this attempts to abstract the problem of iterating over a file
(or multiple files) into a library routine. I've used it a little, but
I don't know the full depths of your use case and/or requirements.

HTH,
Dan

1

rocksolid light 0.9.8
clearnet tor