Simple class in Python error -
i error message saying like:
typeerror: readfromfile() takes 2 arguments (1 given) this first class in python btw.
from numpy import * pycalfem import * pycalfem_utils import * class flowmodel: def __init__(self): self.readfromfile() def readfromfile(self,filename): inputfile=open(filename,'r') ep=readfloat(inputfile) print(str(ep)) inputfile.close() if __name__=="__main__": flowmodel=flowmodel() flowmodel.readfromfile("indata.txt")
you call self.readfromfile() without arguments, when create flowmodel instance:
def __init__(self): self.readfromfile() this means method passed self, first argument, not second argument filename.
remove line; don't have filename pass in there. using method correctly outside of __init__ method after creating instance.
Comments
Post a Comment