Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #196914
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | "Loris Bennett" <loris.bennett@fu-berlin.de> |
| 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> (permalink) |
| 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) |
| Xref | csiph.com comp.lang.python:196914 |
Show key headers only | View raw
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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Using 'with open(...) as ...' together with configparser.ConfigParser.read "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-10-29 14:56 +0100
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-10-29 15:33 +0000
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-10-30 14:03 +0100
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-10-30 15:41 +0000
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-10-30 16:57 +0100
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-10-30 17:57 +0000
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read "Loris Bennett" <loris.bennett@fu-berlin.de> - 2024-10-31 07:47 +0100
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read Jon Ribbens <jon+usenet@unequivocal.eu> - 2024-10-31 08:41 +0000
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read Karsten Hilbert <Karsten.Hilbert@gmx.net> - 2024-10-31 17:10 +0100
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read MRAB <python@mrabarnett.plus.com> - 2024-10-31 17:06 +0000
Re: Using 'with open(...) as ...' together with configparser.ConfigParser.read MRAB <python@mrabarnett.plus.com> - 2024-10-29 16:10 +0000
Re: Using 'with open(...) as ...' (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-10-30 00:10 +0000
csiph-web