@open_file(1, mode='w')
def write_p2g(G, path, encoding='utf-8'):
 path.write(('%s\n' % G.name).encode(encoding))
 path.write(('%s %s\n' % (G.order(), G.size())).encode(encoding))
 nodes = list(G)
 nodenumber = dict(zip(nodes, range(len(nodes))))
 for n in nodes:
  path.write(('%s\n' % n).encode(encoding))
  for nbr in G.neighbors(n):
   path.write(('%s ' % nodenumber[nbr]).encode(encoding))
  path.write('\n'.encode(encoding))

@ open_file ( 1 , mode = 'w' ) def write_p2g ( G , path , encoding = 'utf-8' ) : path . write ( ( '%s\n' % G . name ) . encode ( encoding ) ) path . write ( ( '%s %s\n' % ( G . order ( ) , G . size ( ) ) ) . encode ( encoding ) ) nodes = list ( G ) nodenumber = dict ( zip ( nodes , range ( len ( nodes ) ) ) ) for n in nodes : path . write ( ( '%s\n' % n ) . encode ( encoding ) ) for nbr in G . neighbors ( n ) : path . write ( ( '%s ' % nodenumber [ nbr ] ) . encode ( encoding ) ) path . write ( '\n' . encode ( encoding ) )
write networkx graph in p2g format .