Parsing comments in dot file with python

拜拜、爱过 提交于 2019-12-13 02:27:48

问题


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


回答1:


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']


来源:https://stackoverflow.com/questions/21605588/parsing-comments-in-dot-file-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!