I am reading file path from the following config.ini. And when trying to open the file, python throws no such file or directory exception. But when the same path is hard coded inside python, it successfully locates the file. I use python3.6.7 and linux os.
A section from config.ini
[IO]
SOURCE_DIRECTORY=/mnt/pdrive
python code:
config = configparser.ConfigParser()
config.read("./config.ini")
path = config.get('IO','SOURCE_DIRECTORY')
def exception_handler(exception_object):
print(F"error while walking directory tree {exception_object}")
for dir, sub_dir, file_names in os.walk(top=path, onerror=exception_handler):
print(F"reading dir {dir}")
Following exception is thrown
error while walking directory tree [Errno 2] No such file or directory: '/mnt/pdrive'
And when I hard code the file path instead of reading from confing.ini. it works fine.
path = '/mnt/pdrive'
I have tried forward/backward and double slashes but no success.