Repository: networkx/networkx

Issue:
write_gml does not allow for empty lists as attributes
The write_gml function does not handle empty lists as attributes. I'm not sure if this is expected behaviour.


### Current Behavior
Fails to convert an empty list to a string and raises the error `networkx.exception.NetworkXError: [] is not a string`

### Expected Behavior
I would expect an empty list to be written to the GML file as '[]'

### Steps to Reproduce
```
import networkx as nx
G = nx.complete_graph(4)
G.nodes[0]['test']=[]
nx.write_gml(G,'test.gml')
```

### Environment
Python version: 3.9.5
NetworkX version: 2.5.1



Discussion:
I'm not sure what the "correct" behavior is either - what does the gml standard say about this case?

From the traceback, the problem lives in the default `stringizer`, specifically around: https://github.com/networkx/networkx/blob/dfa1150a9b8cf15183d7c910ff9b67ef3d220513/networkx/readwrite/gml.py#L729

This is what prevents empty lists being used.

Looking around the module a bit more, there is a function called `literal_stringizer` that seems to behave more the way you were expecting, try:

```python
nx.write_gml(G, 'test.gml', stringizer=nx.readwrite.gml.literal_stringizer)
```
Thanks very much for pointing out the alternative stringizer function. 
From what I can tell the GML standard does not specify what should be done in this case.
Incidentally, the link to the GML standard on the Networkx website appears to be out of date and now redirects to an alumnus page: http://www.infosun.fim.uni-passau.de/Graphlet/GML/gml-tr.html
> Incidentally, the link to the GML standard on the Networkx website appears to be out of date and now redirects to an alumnus page: 

This should be fixed (insofar as is possible, as there doesn't seem to be an html version of the spec) in the [latest version of the documentation](https://networkx.org/documentation/latest/reference/readwrite/gml.html)
So, can we make this issue into a request to 

- fix the link to the GML standard
- add the literal_stringizer to the "See Also" section of the doc string.
- maybe include `literal_stringizer` in the main namespace.
  
Anything else?
> So, can we make this issue into a request to
> 
>     * fix the link to the GML standard
This has been fixed in #4864 , though if anyone knows of an active html link (the current link is an archived page from wayback machine that only provides a pdf-version of the GML spec) this could certainly be improved.
>     * add the literal_stringizer to the "See Also" section of the doc string.
+1 for this.
>     * maybe include `literal_stringizer` in the main namespace.
I'm not sure about this one, since it is pretty specialized functionality that only really makes sense in the context of the GML module.
> 
> Anything else?

Makes sense to me - I'd say adding `literal_stringizer` to the `See Also` section of the `read_gml` docstring would be sufficient to close this. 
I agree!  Thanks @rossbar 
Adding `literal_stringizer` to the See Also section should be sufficient.  No need to add it to the main namespace.

Resolving patch:
diff --git a/networkx/readwrite/gml.py b/networkx/readwrite/gml.py
--- a/networkx/readwrite/gml.py
+++ b/networkx/readwrite/gml.py
@@ -144,6 +144,7 @@ def read_gml(path, label="label", destringizer=None):
     See Also
     --------
     write_gml, parse_gml
+    literal_destringizer
 
     Notes
     -----
@@ -622,6 +623,10 @@ def generate_gml(G, stringizer=None):
         If `stringizer` cannot convert a value into a string, or the value to
         convert is not a string while `stringizer` is None.
 
+    See Also
+    --------
+    literal_stringizer
+
     Notes
     -----
     Graph attributes named 'directed', 'multigraph', 'node' or
@@ -813,6 +818,7 @@ def write_gml(G, path, stringizer=None):
     See Also
     --------
     read_gml, generate_gml
+    literal_stringizer
 
     Notes
     -----


Test patch: