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:
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.
CodePudding user response:
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.
CodePudding user response:
PatchFinder is the module that you are calling. To access the PatchFinder class USE
tf = PatchFinder.PatchFinder()
OR import the class like this
from PatchFinder import PatchFinder