|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | | -__author__ = 'ipetrash' |
| 4 | +__author__ = "ipetrash" |
5 | 5 |
|
6 | 6 |
|
7 | 7 | # SOURCE: https://docs.python.org/3/library/xml.etree.elementtree.html |
|
12 | 12 | from pretty_print import indent |
13 | 13 |
|
14 | 14 |
|
15 | | -root = ET.Element('data') |
| 15 | +root = ET.Element("data") |
16 | 16 |
|
17 | | -country = ET.Element('country', name="Liechtenstein") |
| 17 | +country = ET.Element("country", name="Liechtenstein") |
18 | 18 |
|
19 | | -rank = ET.Element('rank', updated="yes") |
20 | | -rank.text = '2' |
| 19 | +rank = ET.Element("rank", updated="yes") |
| 20 | +rank.text = "2" |
21 | 21 | country.append(rank) |
22 | 22 |
|
23 | | -year = ET.Element('year') |
24 | | -year.text = '2008' |
| 23 | +year = ET.Element("year") |
| 24 | +year.text = "2008" |
25 | 25 | country.append(year) |
26 | 26 |
|
27 | | -gdppc = ET.Element('gdppc') |
28 | | -gdppc.text = '141100' |
| 27 | +gdppc = ET.Element("gdppc") |
| 28 | +gdppc.text = "141100" |
29 | 29 | country.append(gdppc) |
30 | 30 |
|
31 | | -country.append(ET.Element('neighbor', name="Austria", direction="E")) |
32 | | -country.append(ET.Element('neighbor', name="Switzerland", direction="W")) |
| 31 | +country.append(ET.Element("neighbor", name="Austria", direction="E")) |
| 32 | +country.append(ET.Element("neighbor", name="Switzerland", direction="W")) |
33 | 33 |
|
34 | 34 | root.append(country) |
35 | 35 |
|
36 | | -country = ET.Element('country', name="Singapore") |
| 36 | +country = ET.Element("country", name="Singapore") |
37 | 37 | root.append(country) |
38 | 38 |
|
39 | 39 | ... |
|
55 | 55 |
|
56 | 56 | etree = ET.ElementTree(root) |
57 | 57 | f = io.BytesIO() |
58 | | -etree.write(f, encoding='utf-8', xml_declaration=True) |
| 58 | +etree.write(f, encoding="utf-8", xml_declaration=True) |
59 | 59 | print(f.getvalue().decode(encoding="utf-8")) |
60 | 60 | # <?xml version='1.0' encoding='utf-8'?> |
61 | 61 | # <data> |
|
0 commit comments