def get_info(filename):
info = {}
with open(filename) as _file:
data = ast.parse(_file.read())
for node in data.body:
if type(node) != ast.Assign:
continue
if type(node.value) not in [ast.Str, ast.Num]:
continue
name = None
for target in node.targets:
name = target.id
if type(node.value) == ast.Str:
info[name] = node.value.s
elif type(node.value) == ast.Num:
info[name] = node.value.n
return info
评论列表
文章目录