1

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))
Barmar
789k57 gold badges555 silver badges669 bronze badges
asked Aug 13, 2020 at 18:00
3
  • 5
    train should be an ordinary method, not a property. Commented Aug 13, 2020 at 18:29
  • 2
    why are you making this a property instead of a regular method? Commented Aug 13, 2020 at 18:29
  • 2
    A property is not a regular class method. If you want to ask about properties, your question title should reflect that. If you want to ask about class methods, your question's body should actually be about regular class methods, not about properties. (@classmethod, not @property). Commented Aug 13, 2020 at 18:30

1 Answer 1

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).

answered Aug 13, 2020 at 19:12
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.