Using 'with open(...) as ...' together with configparser.ConfigParser.read
Jon Ribbens
jon+usenet at unequivocal.eu
Wed Oct 30 11:41:13 EDT 2024
On 2024-10-30, Loris Bennett <loris.bennett at fu-berlin.de> wrote:
> Jon Ribbens <jon+usenet at 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.
More information about the Python-list
mailing list