I find myself often having a function, for example authenticate:
authenticate(user, token):
# do authentication
and a dictionary created by reading a configuration file, like this:
conf['general']['auth_user']
conf['general']['auth_token']
My question is, in terms of best practice (python in specific), should I just call my function by directly giving the arguments, like this:
authenticate(conf['general']['auth_user'], conf['general']['auth_token'])
or should I assign the values into more readable variables and then call the function?
user = conf['general']['auth_user']
token = conf['general']['auth_token']
authenticate(user, token)
Personally, I find the second way more readable, especially when the function needs more than 2 arguments.
'general'
,'auth_user'
, and'auth_token'
strings to constants. I would also make a class that initializes itself from the configuration dictionary, and provides these fields as properties – Alexander - Reinstate Monica Jun 8 '17 at 17:51