Import a variable from a function within a class from one file to another file

Hi All, I have 2 files “” and “”. The has a class “Trainer” with a function “tnr” defined under the class as shown in the image below. I want to access the highlighted variables “edge_logits” and “nodes_logits” in the last line of the and use them in the “reconstruction_scores” function in the file but I have tried all possible options but getting error. As can be seen, I have already imported utils in the file and so when I import trainer in the, it will throw a error as a result of circular imports. Any ideas to help access the “nodes_logits” and “edges_logits” from the and use them in the “reconstruction_scores” function in the are welcomed. Below are the images of the and

You should be able to import MolecularMetrics and use it in via:

edges_logits, nodes_logits = self.G(z)
MolecularMetrics.reconstruction_score(edges_logits, nodes_logits)

PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.

Hi @ptrblck. Thanks for the reply but I want to do the opposite of what you are thinking. I want to import from the and use edge_logits and nodes_logits in the as highlighted under the reconstruction_scores function in the utils image. How do I go about it without incurring circular import errors.
I have already tried importing Trainer class in the by from trainer import Trainer and using Trainer.tnr.nodes_logits and Trainer.tnr.edges_logits in the reconstruction_scores function, but I get circular import error since I have also imported in the

ImportError: cannot import name 'Trainer' from 'trainer'

You won’t be able to access edges_logits or nodes_logits from Trainer.tnr as they are not attributes but local variables.
Maybe return these tensors and call the Trainer class from MolecularMetrics.
To avoid circular imports, check e.g this post.