Deutsch   English   Français   Italiano  
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Jon Ribbens <jon+usenet@unequivocal.eu>
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
 configparser.ConfigParser.read
Date: Wed, 30 Oct 2024 15:41:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
 <slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
 <87bjz1vj2c.fsf@zedat.fu-berlin.de>
Injection-Date: Wed, 30 Oct 2024 16:41:13 +0100 (CET)
Injection-Info: dont-email.me; posting-host="10097155540288a98722c2c8f49dd8a3";
	logging-data="2334097"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18kd4iYT/Fe/PqC9055GyWGg+ZApex62ww="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:1lOpoIyygnF8pqDlmtkP6QKhEqI=
Bytes: 1788

On 2024-10-30, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>> As per the docs you link to, the read() method only takes filename(s)
>> as arguments, if you have an already-open file you want to read then
>> you should use the read_file() method instead.
>
> As you and others have pointed out, this is indeed covered in the docs,
> so mea culpa.
>
> However, whereas I can see why you might want to read the config from a
> dict or a string, what would be a use case in which I would want to
> read from an open file rather than just reading from a file(name)?

The ConfigParser module provides read(), read_file(), read_string(),
and read_dict() methods. I think they were just trying to be
comprehensive. It's a bit non-Pythonic really.