>>> from networkx import *
>>> from networkx.operators import *
>>> import os,tempfile

>>> data="""#header section	  \nLEDA.GRAPH \nstring\nint\n-1\n#nodes section\n5 \n|{v1}| \n|{v2}| \n|{v3}| \n|{v4}| \n|{v5}| \n\n#edges section\n7 \n1 2 0 |{4}| \n1 3 0 |{3}| \n2 3 0 |{2}| \n3 4 0 |{3}| \n3 5 0 |{7}| \n4 5 0 |{6}| \n5 1 0 |{foo}|"""

>>> G=parse_leda(data)

>>> print sorted(G.nodes())
['v1', 'v2', 'v3', 'v4', 'v5']

>>> print [e for e in sorted(G.edges())]
[('v1', 'v2', '4'), ('v1', 'v3', '3'), ('v2', 'v3', '2'), ('v3', 'v4', '3'), ('v3', 'v5', '7'), ('v4', 'v5', '6'), ('v5', 'v1', 'foo')]



>>> (fd,fname)=tempfile.mkstemp()
>>> fh=open(fname,'w')
>>> fh.write(data)
>>> fh.close()
>>> Gin=read_leda(fname)
>>> sorted(G.nodes())==sorted(Gin.nodes())
True
>>> sorted(G.edges())==sorted(Gin.edges())
True
>>> os.close(fd)
>>> os.unlink(fname)

