File: utf8_encoding.py

package info (click to toggle)
python-pygraphviz 1.3.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 664 kB
  • sloc: ansic: 4,970; python: 2,523; makefile: 152
file content (35 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
"""
Example showing use of unicode and UTF-8 encoding.
"""

from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

import pygraphviz as pgv
# specify UTF-8 encoding (it is the default)
A=pgv.AGraph(encoding='UTF-8')

# nodes, attributes, etc can be strings or unicode
A.add_node(1,label='plain string')
A.add_node(2,label='unicode')

# you can enter unicode text as
hello='Здравствуйте!'
A.add_node(3,label=hello)

# or using unicode code points
hello='\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!'
A.add_node(hello) # unicode node label

goodbye="До свидания"
A.add_edge(1,hello,key=goodbye)

A.add_edge("שלום",hello)
#A.add_edge(1,3,hello="こんにちは / コンニチハ")
A.add_edge(1,"こんにちは")

print(A) # print to screen
A.write('utf8.dot') # write to simple.dot