用python解析点文件中的注释 [英] Parsing comments in dot file with python

查看:118
本文介绍了用python解析点文件中的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pydot 来解析python中的点文件。我找不到解析点文件本身的注释的方法,有没有办法做到这一点?



通过查看文档,我无法找到任何答案。

另外,你会建议一个更好的点文件解析器吗(或许更好地维护)比 pydot ?$ / b>

感谢

解决方案

如果你使用模块json,

  import pydot 
import pyparsing
import json


graph = pydot。 graph_from_dot_file(path)
edgeList = graph.get_edge_list()$ b $ for e in edgeList:
tempAttr = json.dumps(e.get_attributes())
edgeAttr = json.loads( tempAttr)
edgeAttr ['insert_label_here']


I'm using pydot for parsing dot files in python. I can't find a way to parse comments present in the dot file itself, is there any way to do it?

By just looking at the documentation I couldn't find any answer.

Also, would you suggest a better parser for dot files (perhaps better maintained) than pydot?

Thanks

解决方案

it is possible if you use the module json along with it like:

import pydot
import pyparsing
import json


graph = pydot.graph_from_dot_file(path)
edgeList = graph.get_edge_list() 
for e in edgeList:
      tempAttr = json.dumps(e.get_attributes())
      edgeAttr = json.loads(tempAttr)
      edgeAttr['insert_label_here']

这篇关于用python解析点文件中的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆