kwargs - Clunky arg check in Python -


i have function:

def check_user(self, **args):     allowed = ['name', 'screen_name', 'url', 'description', 'location']     arg_check = [val val in args if val not in allowed]     if arg_check:         raise valueerror('invalid args: ' + ' '.join(arg_check)) 

and works, feels unpythonic. there better way of checking this? hoping not have write big if/else statement.

this way can iterate on args in loop easily.

i think more pythonic version explicitly declare allowed arguments in function definition. replace none default values.

def check_user(self, name=none, screen_name=none, url=none,                description=none, location=none):     # here     # ... 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -