Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

file path read from a conf.ini file is not locatable in python

$
0
0

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.


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>