Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Fine day to work off excess energy. Steal something heavy.


comp / comp.lang.python / Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read

SubjectAuthor
* Using 'with open(...) as ...' together with configparser.ConfigParser.readLoris Bennett
+* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readJon Ribbens
|`* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readLoris Bennett
| `* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readJon Ribbens
|  `* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readLoris Bennett
|   `* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readJon Ribbens
|    `* Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readLoris Bennett
|     +- Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readJon Ribbens
|     +- Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readKarsten Hilbert
|     `- Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readMRAB
+- Re: Using 'with open(...) as ...' together with configparser.ConfigParser.readMRAB
`- Re: Using 'with open(...) as ...' (Posting On Python-List Prohibited)Lawrence D'Oliveiro

1
Subject: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Loris Bennett
Newsgroups: comp.lang.python
Organization: FUB-IT, Freie Universität Berlin
Date: Tue, 29 Oct 2024 13:56 UTC
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Using 'with open(...) as ...' together with configparser.ConfigParser.read
Date: Tue, 29 Oct 2024 14:56:01 +0100
Organization: FUB-IT, Freie Universität Berlin
Lines: 51
Message-ID: <87plnj3te6.fsf@zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de dQj9cRxdi+Ve6mXTTXiheAmEEnDsu/kKC+DtIDN/0y2HMW
Cancel-Lock: sha1:Yd/PsZWFHRLGDtGBbOGnNbTw1LY= sha1:pO9hnex7f7wgeRmzMpzGOuybeWc= sha256:iSJCuAJmZCy1FheGqTslKIHtys2xG7090FzU/RKCpvs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
View all headers

Hi,

With Python 3.9.18, if I do

try:
with open(args.config_file, 'r') as config_file:
config = configparser.ConfigParser()
config.read(config_file)
print(config.sections())

i.e try to read the configuration with the variable defined via 'with
.... as', I get

[]

whereas if I use the file name directly

try:
with open(args.config_file, 'r') as config_file:
config = configparser.ConfigParser()
config.read(args.config_file)
print(config.sections())
I get

['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 'handler_consoleHandler', 'formatter_defaultFormatter']

which is what I expect.

If I print type of 'config_file' I get

<class '_io.TextIOWrapper'>

whereas 'args.config_file' is just

<class 'str'>

Should I be able to use the '_io.TextIOWrapper' object variable here? If so how?

Here

https://docs.python.org/3.9/library/configparser.html

there are examples which use the 'with open ... as' variable for writing
a configuration file, but not for reading one.

Cheers,

Loris

--
This signature is currently under constuction.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Jon Ribbens
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Tue, 29 Oct 2024 15:33 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Tue, 29 Oct 2024 15:33:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
Injection-Date: Tue, 29 Oct 2024 16:33:58 +0100 (CET)
Injection-Info: dont-email.me; posting-host="1bfe5e6273cf666f3929f3b2c4dd21b2";
logging-data="1707723"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19V203QqUiIKFDUEEJiWd+QwMoB+xlV8XI="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:wjoJOW1xutyaDXPHEylKILc1Awc=
View all headers

On 2024-10-29, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> Hi,
>
> With Python 3.9.18, if I do
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(config_file)
> print(config.sections())
>
> i.e try to read the configuration with the variable defined via 'with
> ... as', I get
>
> []
>
> whereas if I use the file name directly
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(args.config_file)
> print(config.sections())
> I get
>
> ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 'handler_consoleHandler', 'formatter_defaultFormatter']
>
> which is what I expect.
>
> If I print type of 'config_file' I get
>
> <class '_io.TextIOWrapper'>
>
> whereas 'args.config_file' is just
>
> <class 'str'>
>
> Should I be able to use the '_io.TextIOWrapper' object variable here? If so how?
>
> Here
>
> https://docs.python.org/3.9/library/configparser.html
>
> there are examples which use the 'with open ... as' variable for writing
> a configuration file, but not for reading one.

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.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: MRAB
Newsgroups: comp.lang.python
Date: Tue, 29 Oct 2024 16:10 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Tue, 29 Oct 2024 16:10:47 +0000
Lines: 56
Message-ID: <mailman.57.1730218436.4695.python-list@python.org>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<61f0d076-a72e-467d-b4a7-91c1c5792933@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 rmQJ1HO32onG1ozw8Rc58AbxEgTJH3p2w4mKZN6ZUpdg==
Cancel-Lock: sha1:DTi6DwMdSlwUQqOyJ6aJmTwOkLo= sha256:7isa7UpUL4HG9ljUXcr2tkoLQaO/4wzh75EcCFx7scQ=
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=NZwP5Xfg;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'variable': 0.05;
'from:addr:python': 0.09; 'received:192.168.1.64': 0.09;
'cheers,': 0.11; '(it': 0.16; 'bennett': 0.16; 'expects': 0.16;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'instead.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'paths': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16;
'received:plus.net': 0.16; 'treats': 0.16; 'wrote:': 0.16;
'python': 0.16; 'to:addr:python-list': 0.20; 'examples': 0.25;
'object': 0.26; 'header:User-Agent:1': 0.30; 'files,': 0.32;
'python-list': 0.32; 'subject:Using': 0.32; 'but': 0.32;
'received:192.168.1': 0.32; 'there': 0.33; 'path': 0.33; 'header
:In-Reply-To:1': 0.34; 'able': 0.34; 'one.': 0.35; '...': 0.37;
"skip:' 10": 0.37; 'received:192.168': 0.37; 'file': 0.38; 'url-
ip:151.101.0.223/32': 0.38; 'url-ip:151.101.128.223/32': 0.38;
'url-ip:151.101.192.223/32': 0.38; 'url-ip:151.101.64.223/32':
0.38; 'read': 0.38; 'use': 0.39; 'want': 0.40; 'try': 0.40;
'should': 0.40; 'skip:o 20': 0.63; 'here': 0.63; 'i.e': 0.84;
'subject: \n ': 0.84; 'subject:open': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1730218248; bh=USKQpOQ02+qXb0/OteHSJsVR7sZPTi460Y+CJVpYiDw=;
h=Date:Subject:To:References:From:In-Reply-To;
b=NZwP5XfgdQiuWb6JFO28Vv3/rACUEyOVl0cbZFWJg8eO9ULXLPhaRkdg0wgs069zE
E1ORHw6cGD5DTpxseeRTzwd0quiekX7wR6bDd1tu8lWuV1NCw1S29PVBLk852H3O3u
5ZiRLdxJ3A5sz3v2OBqbRtBqyX7jgMr3SfbI/a8itj8tr3id6lcsmqCbvg69xFWGz2
kdiWeL/3yYVEE00wAgpmB9KlwqZimkgrETOO4qlBST53ZGNyGtqSMRVjBXOA+1gFn8
787PG2VdD/QAv9ESHM2E1Z25yvWwZcZ6dkRFrY9mpZY1NqVkRIgvy4zfVRJYlAtTfg
vV/zwlPOEyBsw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=K5mBHDWI c=1 sm=1 tr=0 ts=67210908
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=8AHkEIZyAAAA:8 a=tyeaRgkwHCbBz36ZGYQA:9 a=QEXdDO2ut3YA:10
a=FDWBRInjw0UA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <87plnj3te6.fsf@zedat.fu-berlin.de>
X-CMAE-Envelope: MS4xfIR8nfzLru9QuGsjhmestbpVosiD5zOT98VOj5PpVjfPOyvhX3oN715x8Lxjaym0FXivEhsjsHFtAf5YkKdXV89bC2HuHq+mY+ll3OwERgbuaCIoaw38
vt+IYt/xxdkRrEYWWw3MqlyJRrFw2wYxydVhnTGiGo7SUx5xTtiF2h6Tdm0tKO9in8qC6fufZOeOnPVoTVyem1nJPAIPP0DeD5I=
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: <61f0d076-a72e-467d-b4a7-91c1c5792933@mrabarnett.plus.com>
X-Mailman-Original-References: <87plnj3te6.fsf@zedat.fu-berlin.de>
View all headers

On 2024-10-29 13:56, Loris Bennett via Python-list wrote:
> Hi,
>
> With Python 3.9.18, if I do
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(config_file)
> print(config.sections())
>
> i.e try to read the configuration with the variable defined via 'with
> ... as', I get
>
> []
>
> whereas if I use the file name directly
>
> try:
> with open(args.config_file, 'r') as config_file:
> config = configparser.ConfigParser()
> config.read(args.config_file)
> print(config.sections())
> I get
>
> ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 'handler_consoleHandler', 'formatter_defaultFormatter']
>
> which is what I expect.
>
> If I print type of 'config_file' I get
>
> <class '_io.TextIOWrapper'>
>
> whereas 'args.config_file' is just
>
> <class 'str'>
>
> Should I be able to use the '_io.TextIOWrapper' object variable here? If so how?
>
> Here
>
> https://docs.python.org/3.9/library/configparser.html
>
> there are examples which use the 'with open ... as' variable for writing
> a configuration file, but not for reading one.
>
> Cheers,
>
> Loris
>
'config.read' expects a path or paths. If you give it a file handle, it
treats it as an iterable. (It might be reading the line as paths of
files, but I haven't tested it).

If you want to read from an open file, use 'config.read_file' instead.

Subject: Re: Using 'with open(...) as ...' (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Wed, 30 Oct 2024 00:10 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' (Posting On Python-List Prohibited)
Date: Wed, 30 Oct 2024 00:10:14 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <vfrth6$1p8n1$3@dont-email.me>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 30 Oct 2024 01:10:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="edd39ea38ffff6994a3df0ec9ab6709f";
logging-data="1876705"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Mkf8ODiiGckwyKfgNF2lD"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:y37m6invZejuQHFxQDTwId7tOsY=
View all headers

On Tue, 29 Oct 2024 14:56:01 +0100, Loris Bennett wrote:

> with open(args.config_file, 'r') as config_file:

I never bother with putting files into context managers. This is not a
good idea for files open for writing, but even for read-only files (as
here), CPython will close the file when the object goes out of scope
anyway.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Loris Bennett
Newsgroups: comp.lang.python
Organization: FUB-IT, Freie Universität Berlin
Date: Wed, 30 Oct 2024 13:03 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
Date: Wed, 30 Oct 2024 14:03:55 +0100
Organization: FUB-IT, Freie Universität Berlin
Lines: 65
Message-ID: <87bjz1vj2c.fsf@zedat.fu-berlin.de>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de R/g7l+LNrQYMfsIF9iHcHgx1MxdSRRKE+//oTuT66VRPvh
Cancel-Lock: sha1:77rJOTJcLRAyDM2SJe+klrkcYm0= sha1:kDXkrpFG0nPZ5Kz8WxXHHfypq08= sha256:AEYBlnxLQ+t8RQrtXzkZyShPSTaMYMiq+pZ2nZLb+rA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
View all headers

Jon Ribbens <jon+usenet@unequivocal.eu> writes:

> On 2024-10-29, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>> Hi,
>>
>> With Python 3.9.18, if I do
>>
>> try:
>> with open(args.config_file, 'r') as config_file:
>> config = configparser.ConfigParser()
>> config.read(config_file)
>> print(config.sections())
>>
>> i.e try to read the configuration with the variable defined via 'with
>> ... as', I get
>>
>> []
>>
>> whereas if I use the file name directly
>>
>> try:
>> with open(args.config_file, 'r') as config_file:
>> config = configparser.ConfigParser()
>> config.read(args.config_file)
>> print(config.sections())
>> I get
>>
>> ['loggers', 'handlers', 'formatters', 'logger_root', 'handler_fileHandler', 'handler_consoleHandler', 'formatter_defaultFormatter']
>>
>> which is what I expect.
>>
>> If I print type of 'config_file' I get
>>
>> <class '_io.TextIOWrapper'>
>>
>> whereas 'args.config_file' is just
>>
>> <class 'str'>
>>
>> Should I be able to use the '_io.TextIOWrapper' object variable here? If so how?
>>
>> Here
>>
>> https://docs.python.org/3.9/library/configparser.html
>>
>> there are examples which use the 'with open ... as' variable for writing
>> a configuration file, but not for reading one.
>
> 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)?

Cheers,

Loris

--
This signature is currently under constuction.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Jon Ribbens
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Wed, 30 Oct 2024 15:41 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
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=
View all headers

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.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Loris Bennett
Newsgroups: comp.lang.python
Organization: FUB-IT, Freie Universität Berlin
Date: Wed, 30 Oct 2024 15:57 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
Date: Wed, 30 Oct 2024 16:57:44 +0100
Organization: FUB-IT, Freie Universität Berlin
Lines: 25
Message-ID: <87r07xtwg7.fsf@zedat.fu-berlin.de>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de ZJb681cOzVQx7mDcNVtIxgUcsfsxakUtMIifnk2BFZt/xX
Cancel-Lock: sha1:AYBqgPBdiaG7wlnQY1B28R446Xc= sha1:jDAKxYSfRjjtBeYrYr7TNXCmRZY= sha256:ZWRorQ424letXaqLbdyumn5tk+BSxUSWaFx3lltx3Fo=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
View all headers

Jon Ribbens <jon+usenet@unequivocal.eu> writes:

> 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.

OK, but is there a common situation might I be obliged to use
'read_file'? I.e. is there some common case where the file name is not
available, only a corresponding file-like object or stream?

--
This signature is currently under constuction.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Jon Ribbens
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Wed, 30 Oct 2024 17:57 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Wed, 30 Oct 2024 17:57:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <slrnvi4ss3.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>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
Injection-Date: Wed, 30 Oct 2024 18:57:24 +0100 (CET)
Injection-Info: dont-email.me; posting-host="10097155540288a98722c2c8f49dd8a3";
logging-data="2379586"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186EuWPWyDeNiQekGA5nqLTCNwKq639t9k="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:hh7Tt4iOZCmLLTbxVil4gQaxnMk=
View all headers

On 2024-10-30, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>> 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.
>
> OK, but is there a common situation might I be obliged to use
> 'read_file'? I.e. is there some common case where the file name is not
> available, only a corresponding file-like object or stream?

Well, sure - any time it's not being read from a file. A bit ironic
that the method to use in that situation is "read_file", of course.
In my view the read() and read_file() methods have their names the
wrong way round. But bear in mind this code is 27 years old, and
the read() function came first.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Loris Bennett
Newsgroups: comp.lang.python
Organization: FUB-IT, Freie Universität Berlin
Date: Thu, 31 Oct 2024 06:47 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
Date: Thu, 31 Oct 2024 07:47:17 +0100
Organization: FUB-IT, Freie Universität Berlin
Lines: 42
Message-ID: <87y124db0q.fsf@zedat.fu-berlin.de>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de B74uJ9wHShGnPjA/GB2n6wzLV2jzGfYeE2Ja4tHtnMbog/
Cancel-Lock: sha1:K5zqQyPTkSHDK9CYlaJxusfeeZA= sha1:K2GF0BkAPCe7tfp/A6WeXG9mrzM= sha256:xvZNyRa5fsufs4kx554CL9W9jyBmB4nSY3z9MgvUtI4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
View all headers

Jon Ribbens <jon+usenet@unequivocal.eu> writes:

> On 2024-10-30, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>> 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.
>>
>> OK, but is there a common situation might I be obliged to use
>> 'read_file'? I.e. is there some common case where the file name is not
>> available, only a corresponding file-like object or stream?
>
> Well, sure - any time it's not being read from a file. A bit ironic
> that the method to use in that situation is "read_file", of course.
> In my view the read() and read_file() methods have their names the
> wrong way round. But bear in mind this code is 27 years old, and
> the read() function came first.

Yes, I suppose history has a lot to answer for :-)

However I didn't make myself clear: I understand that there are
different functions, depending on whether I have a file name or a
stream. Nevertheless, I just can't think of a practical example where I
might just have *only* a stream, especially one containing my
configuration data. I was just interested to know if anyone can give an
example.

--
This signature is currently under constuction.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Jon Ribbens
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Thu, 31 Oct 2024 08:41 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Thu, 31 Oct 2024 08:41:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <slrnvi6gli.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>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
<87y124db0q.fsf@zedat.fu-berlin.de>
Injection-Date: Thu, 31 Oct 2024 09:41:23 +0100 (CET)
Injection-Info: dont-email.me; posting-host="6346c536e3f6626217a953335eeef64f";
logging-data="2765670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+bdNnmBBRzGjtUcdO5vKnqXQy45LRs12Q="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:njrHEzwDec+EljcXBWKxQhpCFtc=
View all headers

On 2024-10-31, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>> On 2024-10-30, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>>> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>>> 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.
>>>
>>> OK, but is there a common situation might I be obliged to use
>>> 'read_file'? I.e. is there some common case where the file name is not
>>> available, only a corresponding file-like object or stream?
>>
>> Well, sure - any time it's not being read from a file. A bit ironic
>> that the method to use in that situation is "read_file", of course.
>> In my view the read() and read_file() methods have their names the
>> wrong way round. But bear in mind this code is 27 years old, and
>> the read() function came first.
>
> Yes, I suppose history has a lot to answer for :-)
>
> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream. Nevertheless, I just can't think of a practical example where I
> might just have *only* a stream, especially one containing my
> configuration data. I was just interested to know if anyone can give an
> example.

That was answered the first sentence of my reply. It's a bit vague
because in most of the situations I can think of, one of the other
read_*() methods would probably be more appropriate. But again,
the history is that read_file() was added first (originally called
readfp() ) so it had to handle all cases where the data being read
was not coming from a named filesystem file - e.g. it's coming over
a Unix socket, or an HTTP request, or from a database.

It is good practice in general to provide a method that allows your
class to read data as a stream, if that is appropriate for what
you're doing, so that people aren't unnecessarily forced to load
data fully into memory or write it to a file, as well as perhaps a
convenience method thaat will read from a named file for people who
are doing that.

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: Karsten Hilbert
Newsgroups: comp.lang.python
Date: Thu, 31 Oct 2024 16:10 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: Karsten.Hilbert@gmx.net (Karsten Hilbert)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Thu, 31 Oct 2024 17:10:42 +0100
Lines: 17
Sender: <karsten.hilbert@gmx.net>
Message-ID: <mailman.60.1730391046.4695.python-list@python.org>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
<87y124db0q.fsf@zedat.fu-berlin.de>
<ZyOsAhhUNtIscTey@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 qglLStn9ru/nVb0DquUbqwQ+J5proRWX4MEVoLzoyOhw==
Cancel-Lock: sha1:150xA8GZj7m5NaR82ayCqxmoCf4= sha256:WhoI6iLGl58R3m5Whyi9ujEiJCzJ9btxlZ09bGEtPlk=
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="2048-bit key; unprotected key"
header.d=gmx.net header.i=karsten.hilbert@gmx.net
header.b=Q3r8RLsB; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'stream': 0.04; '31,':
0.05; 'containing': 0.05; 'received:212.227': 0.07; 'example.':
0.09; 'gpg': 0.09; 'karsten': 0.09; 'repository.': 0.09;
'schrieb': 0.09; '1713': 0.16; 'bennett': 0.16; 'functions,':
0.16; 'over,': 0.16; 'stream.': 0.16; "can't": 0.17; 'thu,': 0.19;
'to:addr:python-list': 0.20; 'anyone': 0.25; 'coming': 0.27;
'fact': 0.28; 'think': 0.29; 'subject:Using': 0.32; 'there': 0.33;
'header:In-Reply-To:1': 0.34; "didn't": 0.34; 'source': 0.36;
'example': 0.37; 'file': 0.38; 'data.': 0.40; 'file:': 0.40;
'interested': 0.68; 'depending': 0.70; 'practical': 0.84; 'say,':
0.84; 'subject: \n ': 0.84; 'subject:open': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net;
s=s31663417; t=1730391043; x=1730995843; i=karsten.hilbert@gmx.net;
bh=2fzUQU/uJmLpIArXSgLB/0bPSsR0F9TSc+NW/s0eO3o=;
h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:References:
MIME-Version:Content-Type:In-Reply-To:Content-Transfer-Encoding:
cc:content-transfer-encoding:content-type:date:from:message-id:
mime-version:reply-to:subject:to;
b=Q3r8RLsBRoidguU1HP1rOUZab99P1jfLg5ggf1/9sDm9873f32T25EF2v7M8x+To
nEV9ZzmetaD5o+esEfB0H8K8KgHEU6YwuoxKclczAX8f9B7ZrhqgAEMoRzpbdK3vJ
ruPCJKwWjeQjMxSNNgDwXYgRyPQaY3L1CEREobjvsLvzfNJMaQpuLAv/Yg25kkLN1
9Y1mFKeGCDjr2TPMvded7SKmW9uw78i7laibN8owX1KB6BGFdxJPvq3T6a8QQvknC
0wsE0aGbAKJ43dFZlagZhxINrK79m6asHVqUZ5Ao4YkIXOxFnavukKJUybGy7EvWI
6P6j+FEMfiy6FZFv7g==
X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a
Content-Disposition: inline
In-Reply-To: <87y124db0q.fsf@zedat.fu-berlin.de>
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:+ZyiML2Y2st43j8Gyh9Cmp3QEXRUw/txBlS+K87lVpqjkZBIoCh
ot08FngYW4b/s4AGQi9Hp24DL9oNwEBklB1fzlLk0FKZm4+jkFjpNI/i9dtoj+iLWrAQNf5
ofgcDY7a3n3ygwYloIoltWc0LA/m3IdMdb4Ji2A1NU3HaTWOjK8bN6Qa61ybN0vTRdnCXGY
u8ZgYWvXcngCZmv6e5MCA==
X-Spam-Flag: NO
UI-OutboundReport: notjunk:1;M01:P0:JE3rzos5vYA=;AMs3vRhy3zITOwFUWQg97hQrQSR
//o0ElxyXJd4aesHRswAjLxMGRM2xbGIaUaTv3I5ClfGLv67z/njJuQRwmY/MrUo4cixUW+yT
KHttIyI7MK2BhV8HSciS3wryEPd8Eo36L5LU2l3ahLyX8ekgEaidt6Kxwdq7trKCBRVUjodbk
MN7zfqtf3adgHkqrsz+TDtAXFgIdXYRRJ1hFpXjyJFblVKdO9bXIXZd3k7uxoMsK+dw5C5bFv
UfrFd13J1gZ7Kq7Pczd9Cn7TNLFurcBRMY5pUQi3NuNyMb7tF2V4f7uD4CIzmSXjHEifM2YUI
j7wITrQXdrkvE6C/lXrXjZSu7Oa6LF8Jetf8Pqz4irHu7PprfzXUIWcbxKmqSSdFnQaus+DVv
XbKIRtASuDMwiJs9yByHegPCovjkLtIfMEBzjghSfBy+qIh4ma+5ro5qjJT8G0PIq09mayYcS
ai8uEEGt8PeY9ymg16nbBnoEb7+CDl39khjTZWukSkEunsh0ZDikzU/HogX+y+0A6tZf2BoeK
VmI4Ax/rh8gs+ZBI3aeYlx/DsGdZYxvANwp9L8KCiN+XqoeYAYTBkpZYvLOcE2Iix18GkerY7
HodZ6UiUDUPP7ooDfVXtScN+Jyc8XwvURPCl7ZXwjIDGghRVymmhJRdfxEQNVgbB7bQnPjdUR
rc6XOJsKJ1/yvaZUR7CEz40NIGiqElmQGneESDB9LEGu9Y70ZtUy62HlsR1Iu58R+K/9zZu6i
L8tuygA9+qYNaNbnfyNo74e/FFsPsu+333Tcy69FHo/F+mSxCTJPv2fQFX7amGTmyxsfOJnBo
Zlpougtu9Jcx00Uy7QUbnKxQ==
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: <ZyOsAhhUNtIscTey@hermes.hilbert.loc>
X-Mailman-Original-References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
<87y124db0q.fsf@zedat.fu-berlin.de>
View all headers

Am Thu, Oct 31, 2024 at 07:47:17AM +0100 schrieb Loris Bennett via Python-list:

> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream. Nevertheless, I just can't think of a practical example where I
> might just have *only* a stream, especially one containing my
> configuration data. I was just interested to know if anyone can give an
> example.

Apart from the fact that any data source can be made into a
file: one might have a stream of data coming in over, say,
http, as in a centralized configuration repository.

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

Subject: Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read
From: MRAB
Newsgroups: comp.lang.python
Date: Thu, 31 Oct 2024 17:06 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Using 'with open(...) as ...' together with
configparser.ConfigParser.read
Date: Thu, 31 Oct 2024 17:06:11 +0000
Lines: 46
Message-ID: <mailman.62.1730394380.4695.python-list@python.org>
References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
<87y124db0q.fsf@zedat.fu-berlin.de>
<a88893a0-627d-4d30-83d1-ec91b318bf99@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 PzcuV38OtwBcYApMqgMU/gKp00LCcGW2275lhcvNJB+Q==
Cancel-Lock: sha1:L78kObbyPz2rya0yKD2mMrxVpXo= sha256:J6z3qrlD124zyIAklQVvL04R2Vzjftw0l/wywtcBOWw=
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=JgSz/v68;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'containing': 0.05; ':-)':
0.09; 'docs,': 0.09; 'example.': 0.09; 'from:addr:python': 0.09;
'ok,': 0.09; 'received:192.168.1.64': 0.09; 'string,': 0.09;
'writes:': 0.09; '>>>>': 0.16; '>>>>>': 0.16; '>>>>>>': 0.16;
'bennett': 0.16; 'dict': 0.16; 'file-like': 0.16; 'folder.': 0.16;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'functions,': 0.16; 'indeed': 0.16; 'instead.': 0.16; 'message-
id:@mrabarnett.plus.com': 0.16; 'received:plus.net': 0.16;
'round.': 0.16; 'stream.': 0.16; 'wrote:': 0.16; "can't": 0.17;
'to:addr:python-list': 0.20; 'i.e.': 0.22; 'code': 0.23; 'anyone':
0.25; 'available,': 0.26; 'object': 0.26; 'bit': 0.27; 'function':
0.27; '>>>': 0.28; 'wrong': 0.28; 'think': 0.29; 'header:User-
Agent:1': 0.30; 'takes': 0.31; 'module': 0.31; 'course.': 0.32;
'extract': 0.32; 'python-list': 0.32; 'subject:Using': 0.32;
'but': 0.32; 'received:192.168.1': 0.32; 'there': 0.33; 'header
:In-Reply-To:1': 0.34; "didn't": 0.34; 'trying': 0.35; 'yes,':
0.35; 'files': 0.36; "it's": 0.37; 'example': 0.37; 'others':
0.37; 'received:192.168': 0.37; 'file': 0.38; 'way': 0.38;
'means': 0.38; 'read': 0.38; 'use': 0.39; 'methods': 0.39;
'data.': 0.40; 'situation': 0.40; 'want': 0.40; 'should': 0.40;
'view': 0.60; 'method': 0.61; 'came': 0.65; 'years': 0.65;
'that,': 0.68; 'per': 0.68; 'interested': 0.68; 'obliged': 0.69;
'depending': 0.70; 'covered': 0.75; 'history': 0.75; 'bear': 0.76;
'out,': 0.78; 'practical': 0.84; 'jon': 0.84; 'really.': 0.84;
'subject: \n ': 0.84; 'subject:open': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1730394372; bh=K+PYXZZkWXQmvT7l+0HYMtauLu915RBgIu9elNDjS+c=;
h=Date:Subject:To:References:From:In-Reply-To;
b=JgSz/v68CanU/DPa5ysnBIHBagleW+5yFbf3ln86ktzgd+8BI71cTObgr7vNRUBuq
ozmaU1i0PGghD9AtqgNMQqqpRMbL5Z6PbqpMxb35S2D3q6HA2PbDcr5Uz94dzxBoEC
kT99DxfnD/ms54TZKJu5LeMGECVan6MFnk7dIlIfF0Txr1u2RWyZ4912LK+hQsmMPj
ovjqUEY3aMazwikRvi+7GQkcESEhEtXz7gQZBI0tnml5pD0zhh8DgKe/14T2ef+RCJ
pKjEDkH17KMaY60zn9qrBIqw0fp7z9NU2qAQZHs5UefHdaxJFoRmYZWcHDrSPbmncn
OjGH2L5/ASDew==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=XaAqz555 c=1 sm=1 tr=0 ts=6723b904
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=6DqTnFL-AAAA:8 a=rKRx6uhQ7eibbEicGR4A:9 a=QEXdDO2ut3YA:10
a=hx3MKrCosyGNkMWN68_U:22
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <87y124db0q.fsf@zedat.fu-berlin.de>
X-CMAE-Envelope: MS4xfNExME2sCK47gWbsuXDtcjmvr/DfBjsvp1oC993QAIQLdd/jJK/ICkxjMWAo+u44Etf+Aut5bpcie2ihEJAVxyiAEY3/6gYT09uIeF4i08p5j7wbAX0B
G3UOBg2ZPUAYfpm2oWfSCpwfh8SEThi1Khr/3Y8DeAAuV61TTDhbu0g66h46cV2bE6An3QQoDQlWaHYbzUD2/sTOOHqJBbXo8Hw=
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: <a88893a0-627d-4d30-83d1-ec91b318bf99@mrabarnett.plus.com>
X-Mailman-Original-References: <87plnj3te6.fsf@zedat.fu-berlin.de>
<slrnvi2035.372.jon+usenet@raven.unequivocal.eu>
<87bjz1vj2c.fsf@zedat.fu-berlin.de>
<slrnvi4ksp.372.jon+usenet@raven.unequivocal.eu>
<87r07xtwg7.fsf@zedat.fu-berlin.de>
<slrnvi4ss3.372.jon+usenet@raven.unequivocal.eu>
<87y124db0q.fsf@zedat.fu-berlin.de>
View all headers

On 2024-10-31 06:47, Loris Bennett via Python-list wrote:
> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>
>> On 2024-10-30, Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>>> Jon Ribbens <jon+usenet@unequivocal.eu> writes:
>>>> 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.
>>>
>>> OK, but is there a common situation might I be obliged to use
>>> 'read_file'? I.e. is there some common case where the file name is not
>>> available, only a corresponding file-like object or stream?
>>
>> Well, sure - any time it's not being read from a file. A bit ironic
>> that the method to use in that situation is "read_file", of course.
>> In my view the read() and read_file() methods have their names the
>> wrong way round. But bear in mind this code is 27 years old, and
>> the read() function came first.
>
> Yes, I suppose history has a lot to answer for :-)
>
> However I didn't make myself clear: I understand that there are
> different functions, depending on whether I have a file name or a
> stream. Nevertheless, I just can't think of a practical example where I
> might just have *only* a stream, especially one containing my
> configuration data. I was just interested to know if anyone can give an
> example.
>
What if the config file was inside a zipped folder?

Although I haven't used ConfigParser like that, I have read the contents
of files that are in a zipped folder. It means that I don't have to
extract the file first.

1

rocksolid light 0.9.8
clearnet tor