I code it

Code and Life

Post From Python + Vim

How to load a key-value pair config file

Recently, I want to parse a simple configration file in python, and I
don’t like use other existing libraries, because they are all
full-functionality, just too complex for me.

Finally I found a simple way to do that, code is following:

def loadUserInfo(fileName):
    userinfo = {}
    file = open(fileName, "r")
    while file:
        line = file.readline()
        if len(line) == 0:
        if line.startswith('#'):
        key, value = line.split("=")
        userinfo[key.strip()] = value.strip()

return userinfo

Key features:

  1. Simple enough
  2. Comment supported
  3. Nothing much


Another intersting thing is this blog is post by my vim + python, it’s
cool to write blog in my favorest editor.