1

Here is another basic question for some basic functionality of py2neo (v4) that does not work in the intuitive way.

How to get/print the list of existing relationship types?

In the documentation's graph section of the database page there is a method relationship_types which supposedly returns "The set of relationship types currently defined within the graph.", and I expected it to work like this:

print(graph.relationship_types)

but I get the error 'Graph' object has no attribute 'relationship_types'.

But if that's the case, what does have that attribute? There is no example of using this method on that page (or anywhere else I could find), and I am having trouble with a lot of the basic functionality of py2neo for similar reasons.

Aaron Bramson
  • 1,176
  • 3
  • 20
  • 34

2 Answers2

2
for rel in grap.ralationships:
    print('from:',rel.start_node)
    print('to:',rel.end_node)
    print('drum role.... ding ding ding Rel TYPE:',type(r).__name__) 

list of types of rels:

set([type(r).__name__ for r in in graph.ralationships])

hope this helps some one

Ivan Jacobs
  • 178
  • 1
  • 9
0

The property that you mentioned is not only in V4 but in V3 as well. Chances are that you are not using the property properly.

Here is a really simple example which works for me (v3.1.2). Same code is working on V4.1.0 too.

from py2neo import Graph

graph = Graph("http://localhost:7474", username="USERNAME", password="PASSWORD")

print(graph.relationship_types)
Himanshu Jain
  • 1,809
  • 1
  • 13
  • 23
  • I ran just this code (changing the credentials to match my database, of course), and I get the same error: `'Graph' object has no attribute 'relationship_types'`. getting the info in Cypher from the Neo4j browser worked without trouble. – Aaron Bramson Oct 03 '18 at 08:41
  • @AaronBramson When running the program can you import py2neo and then print(py2neo.__version__) . Just want to make sure the version is same. – Himanshu Jain Oct 03 '18 at 21:01
  • Yeah, I wrote it in the comment above, the version is 4.1.0 – Aaron Bramson Oct 04 '18 at 10:30
  • just trying to make sure that you are running the command with the right python installation in case you have multiple Python installations. Also, have you tried reinstalling the module? – Himanshu Jain Oct 04 '18 at 18:13
  • Yes, I'm running with the right python installation. So far this is the only thing that's broken in py2neo (besides the documentation and currently their website), and I can get the info with cypher, so I'm not going to waste more time with it. It seems to be just a bug. – Aaron Bramson Oct 05 '18 at 02:40