title: Write Pajek files with node labels using python-igraph
body: <p>I am constructing graphs using <code>igraph</code> and writing them out as Pajek (<code>.net</code>) files to use them with another program. The Pajek files are written with numerical indices for vertices rather than vertex labels, so when I read the files into the other program, the labels are gone.</p>
  
  <p>Here's a simple example:</p>
  
  <pre><code>&gt;&gt;&gt; g = ig.Graph(vertex_attrs={'label': ['spam', 'eggs', 'ham']}, edges=[(1,0), (1,2)])
  &gt;&gt;&gt; g.vs.get_attribute_values('label')
  ['spam', 'eggs', 'ham']
  &gt;&gt;&gt; g.write_pajek('file.net')
  
  $ head file.net
  *Vertices 3
  *Edges
  1 2
  2 3
  </code></pre>
  
  <p>Is it possible to change the behavior of <code>write_pajek()</code> to write out the labels instead of just the indices?</p>
  
  <hr>
  
  <p>A kind colleague pointed out that the underlying <code>igraph</code> C library <a href="https://github.com/igraph/igraph/blob/5cea4789827c9da2b424b65246d3b7d9642741e1/src/foreign.c#L2039" rel="nofollow">doesn't have</a> the ability to write out vertex labels.</p>
  
  <p>Here's a workaround:</p>
  
  <pre><code>import igraph as ig
  g = ig.Graph(vertex_attrs={'label': ['spam', 'eggs', 'ham']}, edges=[(1,0), (1,2)])
  g.write_gml('file.gml')
  
  import networkx as nx
  n = nx.read_gml('file.gml')
  nx.write_pajek(n, 'nxfile.net')
  
  $ head nxfile.net
  *vertices 3
  0 0 0.0 0.0 ellipse label spam id 0
  1 1 0.0 0.0 ellipse label eggs id 1
  2 2 0.0 0.0 ellipse label ham id 2
  ...
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>No workaround needed! Thanks to Gabor for pointing out that <code>write_pajek()</code> uses the <code>id</code> attribute, not the <code>label</code> attribute.</p>
  
  <pre><code>&gt;&gt;&gt; g.vs['id'] = g.vs['label'] 
  &gt;&gt;&gt; g.write_pajek('igfile.net') 
  
  $ head igfile.net 
  *Vertices 3 
  1 "spam" 
  2 "eggs" 
  3 "ham" 
  *Edges 
  1 2 
  2 3
  </code></pre>