For example
username_type = 'email'
def get_user_by(email=None, username=None):
if email:
return user.get_by_email(email)
elif username:
return user.get_by_username(username)
get_user_by(username_type = username)
Of course this line won't work
get_user_by(username_type = username)
But I want something like this to make it work
I don't know which type will I get the user from but I want the named argument based on variable
get_user_by(**{username_type: username})def get_user_by(type, value): if type == 'email': return user.get_by_email(value) else ...Then you'll just callget_user_by(type=username_type, username).