Skip to content

Commit b3ce3f3

Browse files
committed
gh-127011: Add __str__ and __repr__ to ConfigParser
1 parent 30aeb00 commit b3ce3f3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/configparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,14 @@ def __iter__(self):
10401040
# XXX does it break when underlying container state changed?
10411041
return itertools.chain((self.default_section,), self._sections.keys())
10421042

1043+
def __str__(self):
1044+
config_dict = {section: dict(self.items(section)) for section in self.sections()}
1045+
return str(config_dict)
1046+
1047+
def __repr__(self):
1048+
return f"<ConfigParser(default_section='{self.default_section}', interpolation={self._interpolation})>"
1049+
1050+
10431051
def _read(self, fp, fpname):
10441052
"""Parse a sectioned configuration file.
10451053

0 commit comments

Comments
 (0)