You need to use the .read_file()
method on your config
instance instead:
with open('RecorderMover.config.ini', 'r', encoding='utf-8') as f:
config.read_file(f)
The .read()
method treats f
as a sequence of filenames instead, and as none of the lines could ever be interpreted as a filename, the configuration ends up empty.
Alternatively, pass in the filename and encoding to .read()
without opening the file yourself:
config = configparser.ConfigParser()
config.read('RecorderMover.config.ini', encoding='utf-8')
If your input file contains a UTF-8 BOM (\ufeff
, a Microsoft devation from the UTF-8 standard) either create the file using a tool that doesn't add that character (e.g. not Notepad), use the utf_8_sig
codec to open it:
config = configparser.ConfigParser()
config.read('RecorderMover.config.ini', encoding='utf-8-sig')