-1

I'm getting an error on a script straight out of the user guide. What am I doing wrong?

import graph_tool.all as gt
print gt.__version__
g = gt.Graph()
g.add_vertex(5)
g.get_vertices()

returns

2.20 (commit f6ef9990, Fri Jan 27 16:40:08 2017 +0000)
Traceback (most recent call last):
File "Untitled.py", line 7, in
g.get_vertices()
AttributeError: 'Graph' object has no attribute 'get_vertices'

Tim
  • 171
  • 2
  • 12

2 Answers2

0

You're probably mixing the attributes of a Graph in graph-tool with those of another graphing library in Python. To get all vertices, use g.vertices().

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
  • I'm looking for an array to be returned, which is what `get_vertices()` gives me. `g.vertices()` returns an iterator object. I could follow `g.vertices()` with a loop that adds each item from the iterator to a list, but that would be O(n). I'd really prefer to figure out how to get `get_vertices()` working. – Tim Feb 21 '17 at 15:11
  • You can get an array with `list(g.vertices())` – Moses Koledoye Feb 21 '17 at 15:23
0

The attribute Graph.get_vertices() is only available in the git version of the library, not the version 2.20 that you are using. It is only mentioned in the development version of the documentation, not the main guide.

Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28