0

I keep getting a NameError in my Python 3.7 code that I don't understand. I know the problem is indentation. From what I can tell my indentation is in order. So I am unsure where this Nameerror is coming from. Any pointers to the problem are appreciated.

Exception has occurred: NameError
name '_loadconfigfile' is not defined

Method call:

 from configsettings import *
settingsfile = configSettings("setting.json")

Class causing problem:

import os
from logextension import *


class configSettings():
    def __init__(self, settingsfilepath=None):
        _loadconfigfile(settingsfilepath)

    def _loadconfigfile(self, settingsfilepath):
        configsettings = None
        try:
            if not os.path.exists(settingsfilepath):
                raise IOError
            else:
                configSettings = open(settingsfilepath, "r")
        except IOError as err:
            msg = "Error reading file" + settingsfilepath + " "+err
            _errorlogging(msg)
        return configSettings

    def _errorlogging(self, msg):
        logger = UserdefinedLogging(__name__, 'configsettings.log', True)
        logger.error(msg)
Gerardsson
  • 322
  • 3
  • 9
  • 1
    To call a method inside another method, you need to use `self`, that's the only reference to the instance which exists. – juanpa.arrivillaga Apr 20 '20 at 09:25
  • Thanks. It's a pity that the code checker doesn't recognize this as an error. This is the second time that I had to look for this error. – Gerardsson Apr 20 '20 at 09:31

0 Answers0