Why this code raises error:
import configparser
import os
path = '/home/solus/Downloads/TestOnMe'
os.chdir(path)
config = configparser.ConfigParser()
config.read('extensions.ini')
extensions = config['Extensions']
But on contrary this code works flawlessly:
import configparser
import os
config = configparser.ConfigParser()
config.read('extensions.ini')
extensions = config['Extensions']
The error is following:
Traceback (most recent call last):
File "/home/solus/Documents/Projects/Python/Learning Python from YT/Own/configurator/testtesttest.py", line 11, in <module>
extensions = config['Extensions']
File "/usr/lib/python3.6/configparser.py", line 959, in __getitem__
raise KeyError(key)
KeyError: 'Extensions'
Content of extensions.ini:
[Extensions]
music = ['mp3', 'acc']
photos = ['jpeg', 'jpg', 'png']
archives = ['rar', 'zip', 'tar', 'tar.bz', 'tar.gz']
documents = ['epub', 'pdf', 'doc']
Both Python file and .ini file are in the same directory.