Re: Configparser question

Gisle Vanem via Python-list <[email protected]> Mon, 30 Mar 2026 17:30:42 +0200
Newsgroups gmane.comp.python.general
Message-ID <[email protected]>
Mats Wichmann wrote:

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

That was not obvious, but much simpler:
  config = configparser.ConfigParser (strict=False, inline_comment_prefixes=("#"))
  config.read ("config.ini")

Thanks!

-- 
--gv