# -*- coding: utf-8 -*- >>> from pygraphviz import * >>> A = AGraph(name=u'unicode') >>> print A strict graph unicode { } # node encoding >>> A = AGraph(encoding='UTF-8') >>> hello='Здравствуйте!'.decode('UTF-8') >>> A.add_node(hello) >>> n=A.get_node(hello) >>> n.name==hello True >>> unicode(A) u'strict graph {\n\tgraph [encoding="UTF-8"];\n\t"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!";\n}\n' # set node attribute >>> n.attr['goodbye']="До свидания".decode('UTF-8') >>> n.attr {u'goodbye': u'\u0414\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'} >>> n.attr['goodbye']=="До свидания".decode('UTF-8') True # edge encoding >>> A = AGraph(encoding='UTF-8') >>> hello="שלום".decode('UTF-8') >>> A.add_edge(hello,hello,key=1) # self loop >>> e=A.get_edge(hello,hello) >>> e.name u'1' >>> e==(hello,hello) True >>> unicode(A) u'strict graph {\n\tgraph [encoding="UTF-8"];\n\t\u05e9\u05dc\u05d5\u05dd -- \u05e9\u05dc\u05d5\u05dd [key=1];\n}\n' # set edge attribute >>> e.attr['hello']=hello >>> e.attr['hello']==hello True >>> e.attr {u'hello': u'\u05e9\u05dc\u05d5\u05dd'} # test unicode in from_string() >>> t = u'测试' >>> G =AGraph() >>> G.add_node(t) >>> ug = unicode(G) >>> sg = str(G) >>> G1 = AGraph(ug) >>> G2 = AGraph(sg) >>> unicode(G1) u'strict graph {\n\t\xe6\xb5\x8b\xe8\xaf\x95;\n}\n' >>> unicode(G2) u'strict graph {\n\t\xe6\xb5\x8b\xe8\xaf\x95;\n}\n'