config.ini
[datasource]
host = localhost
config.py
import configparser
import os
config = configparser.ConfigParser()
config.read(os.path.join(os.getcwd(), 'config.ini'))
host = config['datasource']['host']
Test.py
import config
print(config.host)
Traceback (most recent call last):
File "Test\test.py", line 6, in
import config
File "C:\Users\jack\PycharmProjects\Test\config.py", line 6, in
host = config['datasource']['host']
File "C:\Users\jack\AppData\Local\Programs\Python\Python37-32\lib\configparser.py", line 958, in getitem
raise KeyError(key)
KeyError: 'datasource'
All the files are put in the same folder.
When I run Test.py script from the pycharm it does not have problem.
But when I calling from terminal the error come.
How to solve this problem?