I am trying to get to grips with working with objects in python and have encountered an error which is confusing me. I have added the following property to a class:
@property
def train(self, index):
return self.make_dataset(self.train_df[index])
I want to pass it the argument 'index' so that I can call this function during a training loop. However when I try this with the following code, I get the error:
train() missing 1 required positional argument: 'index'
Even though I did pass the argument as below. I have been looking on the internet but still can't work out what the route cause of the warning is. Is this an incorrect way to mass an argument to a method?
for train_loop in range(len(train_df)):
history = model.fit(multi_window.train(train_loop))
1 Answer 1
Remove the @property decorator:
def train(self, index):
return self.make_dataset(self.train_df[index])
This will make it an instance method, callable by an object of the class (if that's what you'd like it to be).
trainshould be an ordinary method, not a property.@classmethod, not@property).