Page 1 of 1

import ConfigParser error

Posted: Thu Jan 16, 2014 2:18 pm
by mister-man
Hay,

I try to import configparser, but it i found an error.
I tried to fix it, but I can't find the error.

MyCode:

Code: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Reads configs or cfg files
import ConfigParser
     

# =============================================================================
# >> CLASSES
# =============================================================================

class inicfg(object):
    def __init__(self, path, file):
        self.__filepath = str(path) + str(file)
        self.__path = path
        self.__file = file
        config = ConfigParser.RawConfigParser()
       
    def addSection(self, section):
        config.add_section(section)
       
    def setKeyvalue(self, section, key, value):
        config.set(section, key, value)
       
    def save(self):
        with open(self.__filepath, 'wb') as configfile:
            config.write(configfile)


Error:

Code: Select all

[SP]  Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\addons\manager.py', line
48, in __missing__
    instance = _LoadedAddon(addon_name)
  File '..\addons\source-python\packages\source-python\addons\manager.py', line
237, in __init__
    self._addon = __import__(addon_name + '.' + addon_name)
  File '..\addons\source-python\plugins\premium\premium.py', line 26, in <module
>
    from premium._libs import inicfg

ImportError: cannot import name inicfg


[SP] Addon 'premium' was unable to be loaded.

Posted: Thu Jan 16, 2014 4:03 pm
by mister-man
I found my misstake, "import ConfigParser" should " import configparser

Posted: Fri Jan 17, 2014 1:52 am
by satoon101
Just so you know, we already include ConfigObj with SP. I find it much easier to use to parse ini files than configparser. We use it in the translations package within the Python API.

Satoon