(filename)
return cfgdict
Convert content of config-file into dictionary.
Convert content of config-file into dictionary.
Convert content of config - file into dictionary .
def config_dict(filename):
    """Convert content of config-file into dictionary."""
    with open(filename, "r") as f:
        cfglines = f.readlines()
    cfgdict = {}
    for line in cfglines:
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        try:
            key, value = line.split("=")
        except ValueError:
            print("Bad line in config-file %s:\n%s" % (filename,line))
            continue
        key = key.strip()
        value = value.strip()
        if value in ["True", "False", "None", "''", '""']:
            value = eval(value)
        else:
            try:
                if "." in value:
                    value = float(value)
                else:
                    value = int(value)
            except ValueError:
                pass # value need not be converted
        cfgdict[key] = value
    return cfgdict
def config_dict ( filename ) : with open ( filename , "r" ) as f : cfglines = f . readlines ( ) cfgdict = { } for line in cfglines : line = line . strip ( ) if not line or line . startswith ( "#" ) : continue try : key , value = line . split ( "=" ) except ValueError : print ( "Bad line in config-file %s:\n%s" % ( filename , line ) ) continue key = key . strip ( ) value = value . strip ( ) if value in [ "True" , "False" , "None" , "''" , '""' ] : value = eval ( value ) else : try : if "." in value : value = float ( value ) else : value = int ( value ) except ValueError : pass # value need not be converted cfgdict [ key ] = value return cfgdict