Is there a way to define macro-like code to use inside many functions which handle the same data (arguments of the same nature with the same name)? I have many function like “f” below (almost the same interface, they do different things, on the same kind of data). And I have to repeat the same argument validation code for each one.
def f(arg1, arg2, ...):
# validation code
# it checks and eventually change arg1, arg2, etc.
# function code
Is there a way to define a “validation_macro” and then do something like this?
def f(arg1, arg2, ...):
# expand validation_macro
# function code
New contributor
Jean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.