Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting File one (have two classes and functions) elements in file two in Python

I have a file (PatchFinder.py) with two classes:

class PatchFinder():
    
  def __init__(self, dataset, pf: float):
        #super(TopFeatures, self).__init__()
        self.pf = pf
        self.dataset = dataset
        self.datas = dataset[0].to('cpu')

    def TopFeaturesFind(self, g: Graph) -> Graph:
        Zxx, self.edge_index_, edge_weights = g.unfold()
        print(self.pf)
        print(Zxx)
        print(self.edge_index_)
        print(edge_weights)
        return Zxx
    def anotherMethod(self):
        print("something")

2nd class

 class Class2(torch.nn.Module):
    def __init__(self, dataset, hidden_channels):
        super(GCN, self).__init__()

    def forward(self, x, edge_index_):
        return x

Now in another File2.py I want to get the TopFeaturesFind() values. This is what i am doing:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import PatchFinder
def main():
    tf = PatchFinder()
    t=tf.TopFeaturesFind()
    print(t)
if __name__ == '__main__':
    main()

but i am getting error:

    tf = PatchFinder()
TypeError: 'module' object is not callable

What I am doing wrong here? I am from a java background. This seems ok to me. As far as i read

As stated: “Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. source

Note: I don’t want to inherit the PatchFinder, both files are in the same folder.

>Solution :

Your import PatchFinder imports the module, so when you call PatchFinder() you are trying to "initialise" the module, not the class. There’s guidance here: https://docs.python.org/3/tutorial/modules.html

All you need to do is specify that you want to initialise the object defined within the module. Change tf = PatchFinder() to tf = PatchFinder.PatchFinder() and it should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading