preprocess.py 文件源码

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

项目:sciencebeam-gym 作者: elifesciences 项目源码 文件源码
def parse_color_map(f):
  color_map_config = ConfigParser()
  color_map_config.readfp(f)

  num_pattern = re.compile(r'(\d+)')
  rgb_pattern = re.compile(r'\((\d+),(\d+),(\d+)\)')

  def parse_color(s):
    m = num_pattern.match(s)
    if m:
      x = int(m.group(1))
      return (x, x, x)
    else:
      m = rgb_pattern.match(s)
      if m:
        return (int(m.group(1)), int(m.group(2)), int(m.group(3)))
    raise Exception('invalid color value: {}'.format(s))

  color_map = dict()
  for k, v in color_map_config.items('color_map'):
    color_map[parse_color(k)] = parse_color(v)
  return color_map
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号