Discussion Forum

AttributeError: '_Entity' object has no attribute 'get_value'

The implementation is here: Colab

Ultimately I’m trying to demo TypeDB’s inference capabilities to confirm it’s right for our project.

Before that though I want to show the mother, father, child relationship I created but I’m getting an error trying to access the values.

If there is some detailed documentation on how to get query results in python, please point me to it (something more than what’s here).

Honestly, your code is looking pretty great! We’re also excited to see us being used in Google Colab – is it ok if we keep a link to your colab and reference it in our community of an example of how to run TypeDB, and a client, in one Colab? Happy to credit if we get a name/company as well!

The error is right at the bottom:
db_val = answer.get("father1").get_value()
father1 is only going to represent entity instances, which do not have an get_value() method available on them - only attributes have this method.

The only other thing I’d feedback is that re-opening a client in method is not particularly efficient. It’s more idiomatic to open and store a client for the whole class, or even a session if you know all the methods will be used in proximity to each other, then open a session+transaction or just a transaction.

There’s a couple more example projects here: GitHub - vaticle/typedb-examples: TypeDB Examples Projects and Tutorials

Cheers!

Sure, you can reference my code. You can credit it to Chris Smyth.

I suggest using this one instead. It works and is cleaner:

Thanks!

Did you get it working after those suggestions?

Attribute errors in Python are generally raised when you try to access or call an attribute that a particular object type doesn’t possess. It’s simply because there is no attribute with the name you called, for that Object. This means that you got the error when the “module” does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the source code after you had already imported the file (module). Or, some times packages get deprecated and they rename some functions. If that is true, then you may want to exit and reimport the module once again to be able to access the new method .

You can do it in another way to reimport the module with changes without having to exit the interpreter is to do the following:

reload(myModule)

If you are using python 3.2 or 3.3 you should:

import imp
imp.reload(myModule)

If running Python 3.4 and up, do import importlib, then do:

import importlib
importlib.reload(myModule)

The importlib.reload() method reload a previously imported module. The argument must be a module object, so it must have been successfully imported before .