I'm relatively new to python and working with notebooks, but I am having problems with the config.txt file. I think the problem is from the notebook being in a separate file as the module I import (the config.txt file is in the same directory as the imported module). When I run the module in the notebook, I get the 'NoSectionError: No section:' error. However, when I copy and paste the code into the notebook, the code runs just fine. Is there a problem with the working directory?
from src.data import psql_operations
db_connection = psql_operations.PostgresConnection()
class PostgresConnection:
def __init__(self):
config = configparser.ConfigParser()
config.read(r....'/src/data/config.txt')
self.host = config.get('psql database', 'host')
self.db_name = config.get('psql database', 'db_name')
self.user = config.get('psql database', 'user')
self.password = config.get('psql database', 'password')
self.port = config.get('psql database', 'port')
vs.
config = configparser.ConfigParser()
config.read(r.....'/src/data/config.txt')
host = config.get('psql database', 'host')
db_name = config.get('psql database', 'db_name')
user = config.get('psql database', 'user')
password = config.get('psql database', 'password')
port = config.get('psql database', 'port')