class ValidateStrategy(abc.ABC):
def validate(self, input_string):
pass
class IntValidateStrategy(ValidateStrategy):
def validate(self, input_string):
try:
int(input_string)
return True
except ValueError:
return False
def string_validate(input_string, validate_strategy):
return validate_strategy.validate(input_string)
string_validate("22", IntValidateStrategy)
Why am I getting an error because the self argument is missing?
> Traceback (most recent call last): File "F:\Pobrane\drive\test.py",
> line 11, in <module>
> print(el + ": " + str(validator.string_validate(el, validator.IntValidateStrategy))) File
> "F:\Pobrane\drive\validator.py", line 34, in string_validate
> return validate_strategy.validate(input_string) TypeError: IntValidateStrategy.validate() missing 1 required positional argument:
> 'input_string'
validator.string_validate("22", validator,IntValidateStrategy())? Either that or you can make the validate function into a static function, allowing you to call it on the class without passing in a "self" isntance.