Write a graph `G` in GML format to the file or file handle `path`. Parameters ---------- G : EasyGraph graph The graph to be converted to GML. path : filename or filehandle The filename or filehandle to write. Files whose names end with .gz or .bz2 will be c
(G, path, stringizer=None)
| 660 | |
| 661 | @open_file(1, mode="wb") |
| 662 | def write_gml(G, path, stringizer=None): |
| 663 | """Write a graph `G` in GML format to the file or file handle `path`. |
| 664 | |
| 665 | Parameters |
| 666 | ---------- |
| 667 | G : EasyGraph graph |
| 668 | The graph to be converted to GML. |
| 669 | |
| 670 | path : filename or filehandle |
| 671 | The filename or filehandle to write. Files whose names end with .gz or |
| 672 | .bz2 will be compressed. |
| 673 | |
| 674 | stringizer : callable, optional |
| 675 | A `stringizer` which converts non-int/non-float/non-dict values into |
| 676 | strings. If it cannot convert a value into a string, it should raise a |
| 677 | `ValueError` to indicate that. Default value: None. |
| 678 | |
| 679 | Raises |
| 680 | ------ |
| 681 | EasyGraphError |
| 682 | If `stringizer` cannot convert a value into a string, or the value to |
| 683 | convert is not a string while `stringizer` is None. |
| 684 | |
| 685 | See Also |
| 686 | -------- |
| 687 | read_gml, generate_gml |
| 688 | literal_stringizer |
| 689 | |
| 690 | Notes |
| 691 | ----- |
| 692 | Graph attributes named 'directed', 'multigraph', 'node' or |
| 693 | 'edge', node attributes named 'id' or 'label', edge attributes |
| 694 | named 'source' or 'target' (or 'key' if `G` is a multigraph) |
| 695 | are ignored because these attribute names are used to encode the graph |
| 696 | structure. |
| 697 | |
| 698 | GML files are stored using a 7-bit ASCII encoding with any extended |
| 699 | ASCII characters (iso8859-1) appearing as HTML character entities. |
| 700 | Without specifying a `stringizer`/`destringizer`, the code is capable of |
| 701 | writing `int`/`float`/`str`/`dict`/`list` data as required by the GML |
| 702 | specification. For writing other data types, and for reading data other |
| 703 | than `str` you need to explicitly supply a `stringizer`/`destringizer`. |
| 704 | |
| 705 | Note that while we allow non-standard GML to be read from a file, we make |
| 706 | sure to write GML format. In particular, underscores are not allowed in |
| 707 | attribute names. |
| 708 | For additional documentation on the GML file format, please see the |
| 709 | `GML url <https://web.archive.org/web/20190207140002/http://www.fim.uni-passau.de/index.php?id=17297&L=1>`_. |
| 710 | |
| 711 | See the module docstring :mod:`easygraph.readwrite.gml` for more details. |
| 712 | |
| 713 | Examples |
| 714 | -------- |
| 715 | >>> G = eg.path_graph(4) |
| 716 | >>> eg.write_gml(G, "test.gml") |
| 717 | |
| 718 | Filenames ending in .gz or .bz2 will be compressed. |
| 719 |
nothing calls this directly
no test coverage detected