I am trying to read a configuration file in python 3.7 using SafeConfigParser. I have tried giving the full file name (with file location), giving only file name (without file location), using readfp function in SafeConfigParser, using only configparser instead of safeconfigparser but none of them have worked. I am 100% sure that at least the correct file is being read.
Here is my python code:
from configparser import SafeConfigParser
import os
def main():
filename = "C:/Users/Umer Sherdil Paracha/Desktop/distutils.cfg"
if os.path.isfile(filename):
parser = SafeConfigParser()
parser.read(filename)
print(parser.sections())
screen_width = parser.getint('graphics','width')
screen_height = parser.getint('graphics','height')
else:
print("Config file not found")
if __name__=="__main__":
main()
and here is my cfg file:
[GRAPHICS]
height = 600
width = 800
I am totally stuck on this stupid problem. Any help in this regard would be appreciated. Thank you.