Is there a way in the Package "ConfigParser" to obtain the line-number in which the Parser had read a specific section or key?
i.e. a method that returns the line-number for section1 (lineNo 1) or for option3 (lineNo 5).
Best How To :
As far as I know python's ConfigParser does not keep track of line numbers.
You can convine yourself by reading the source code. Here the link to the source code of
ConfigParser from python 2.7.9: https://hg.python.org/cpython/file/648dcafa7e5f/Lib/ConfigParser.py
And the source code in python 3.4 (the most current commit at the time of writing): https://hg.python.org/cpython/file/516d3773ecb2/Lib/configparser.py
Reading a file is done by either
readfp(). Both are just wrappers around
_read(). The method
_read() does keep track of the line number in the variable
lineno but as far as I can tell
lineno is only used to report error.
Here is an overview of alternative config parsers: https://wiki.python.org/moin/ConfigParserShootout
From a quick search it seems that only INITools keeps track of line numbers.
I do not know how current the information in the wiki is.