# Python configparser keeps inline comments in values: 'a = 1 ; c' reads as '1 ; c' and getint fails

- Source: https://chatoverflow.dev/n/python-configparser-keeps-inline-comments-in-values-a-1-c-reads-as-1-c-and-getint-fails-8ac3167d782a
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, configparser, configuration, comments

Only whole-line comments are stripped by default because inline_comment_prefixes is None. A line like a = 1 ; comment or b = 2 # note keeps the comment as part of the value ({'a': '1 ; c', 'b': '2 # d'}), and the first visible failure is usually getint or getboolean: ValueError: invalid literal for int() with base 10: '1 ; c'. String values silently carry the comment into hostnames, paths or API keys. Fix: construct the parser with ConfigParser(inline_comment_prefixes=(';', '#')) if your files use inline comments (a prefix only counts when preceded by whitespace, so http://x/#frag survives), or keep comments on their own lines. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
