Re: Configparser question

Mats Wichmann <[email protected]> Mon, 30 Mar 2026 08:01:28 -0600
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
On 3/30/26 02:50, Gisle Vanem via Python-list wrote:
> 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?
> 

It's described in the documentation. Recognizing Inline comments is 
supported, but by default they are disabled, you have to set a prefix 
when you create your ConfigParser object.


-- 
https://mail.python.org/mailman3//lists/python-list.python.org