main.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:scum 作者: CCareaga 项目源码 文件源码
def read_config():
    counter = 0
    new_config = CONFIG # make a copy of the default config
    with open(CONFIG_PATH, 'r') as f:
        lines = [x.strip('\n') for x in f.readlines()] # strip any unempty lines

    for line in lines:
        counter += 1
        if line.strip() and line.lstrip()[0] != '#': # skip lines with '#' at beginning
            split = line.split(':') # break the line into two parts item and attributes
            item = split[0].strip()
            if item in palette_items: # if this line is a palette line
                attribs = split[1].strip().split(",")
                try: # try creating an urwid attr spec
                    a = urwid.AttrSpec(attribs[0].strip(), attribs[1].strip(), colors=256)
                    if attribs[2] not in text_options:
                        attribs[2] = ''
                    new_config[item] = [item]+[a.foreground, a.background, attribs[2]] # add this to the new config
                except:
                    print("error on line" + str(counter))
            else: # this line isn't a palette lime
                if item in new_config: # if this item exists in config dict
                    new_config[item] = split[1].strip() # redefine it in the dict

    return new_config
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号