3

有谁知道如何将aDigraph转换为io.StringIOpng的技巧?我能找到的唯一代码是将它保存到磁盘,但我想省略任何磁盘使用情况,而是在内存中处理它:

from graphviz import Digraph
import io

dot = Digraph(comment='The Round Table')
dot.node('A', 'King Arthur')

# instead of this...
dot.render('test-output/round-table.gv', view=True)

# ... I need something like this:
data = io.StringIO()
dot.export_to_png(dot)
4

1 回答 1

2

像这样的东西?

from graphviz import Digraph
import io

dot = Digraph(comment='The Round Table', format='gv')
dot.node('A', 'King Arthur')

data = io.StringIO()

print("writing")
data.write( dot.pipe().decode('utf-8') )

print("reading")
data.seek(0)
print(data.read())

# print(data.getvalue())


data.close()
于 2018-12-16T21:37:59.677 回答