0

I try to load config from file with read

But when it reads from same folder it works

When I read from parent it doesn’t.

Code:

/
config.ini
Conf/
    __init__.py
    config.ini
    Conf.py

// Conf.py

config = ConfigParser()

#this works
config.read(‘config.ini’)

#this doesn’t 
config.read(‘./../config.ini’)

Any ideas?

Thanks!

Tzook Bar Noy
  • 11,337
  • 14
  • 51
  • 82

2 Answers2

0

Just tried the same thing here, and both work:

import configparser

config = configparser.ConfigParser()

#this works
print(config.read('config.ini'))

#this works too
print(config.read('./../config.ini'))
progmatico
  • 4,714
  • 1
  • 16
  • 27
0

This solved my question in the end:

import configparser
import os.path

conf = configparser.ConfigParser()

conf.read(os.path.dirname(__file__)+'/../config.ini')
Tzook Bar Noy
  • 11,337
  • 14
  • 51
  • 82