Merge pull request #28 from jaicis/py3convert

Solved BMConfigParser's safeGetInt method issues
This commit is contained in:
jaicis 2020-01-15 13:46:59 +05:30 committed by GitHub
commit 946cfe4627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,13 +99,11 @@ class BMConfigParser(configparser.ConfigParser):
def safeGetInt(self, section, field, default=0): def safeGetInt(self, section, field, default=0):
"""Return value as integer, default on exceptions, """Return value as integer, default on exceptions,
0 if default missing""" 0 if default missing"""
config = configparser.ConfigParser()
try: try:
# Used in the python2.7 # Used in the python2.7
# return self.getint(section, field) # return self.getint(section, field)
# Used in the python3.5.2 # Used in the python3.7.0
return config.getint(section, field) return int(self.get(section, field))
except (configparser.NoSectionError, configparser.NoOptionError, except (configparser.NoSectionError, configparser.NoOptionError,
ValueError, AttributeError): ValueError, AttributeError):
return default return default