有什么办法可以简化下面的代码:
def get_or_create_user(id, photo=None, first_name=None, last_name=None, nickname=None, organization=None, city=None, country=None):
... # save user in the datastore
class UserCreationHandler(webapp.RequestHandler):
def get(self):
id = self.request.get('id')
photo = None
first_name = None
last_name = None
nickname = None
organization = None
city = None
country = None
if something1:
# do some calculations
if something2:
# do some other calculations
if something3:
# assign id, photo, first_name etc. values
get_or_create_user(id, photo, first_name, last_name, nickname, organization, city, country)
我不喜欢将这些分配给 None。
请您参考如下方法:
类似于:
def get(self):
id = self.request.get('id')
user_details = {}
if something:
# assign user_details['id'], user_details['photo'], user_details['first_name'] etc. values
get_or_create_user(id, **user_details)
