Configparser question
Gisle Vanem via Python-list <[email protected]> Mon, 30 Mar 2026 10:50:06 +0200
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
Hello list.
I use 'configparser' with a 'config.ini' like this:
[Audio]
ATC_STREAM_URL = https://s1-fmt2.liveatc.net/vhhh5 # Hong Kong ATC.
# ...
Some of my code:
import configparser
config = configparser.ConfigParser()
config.read ("config.ini")
ATC_STREAM_URL = config.get ("Audio", "ATC_STREAM_URL", fallback="")
But the trailing comment in 'ATC_STREAM_URL = ..' is NOT removed.
A fix I use instead is to read the whole 'config.ini' myself,
strip the trailing comments and call
'config.read_string (fixed_lines)' instead.
But is there a simple way for all this?
--
--gv