gpt4 book ai didi

Python None 变量用法

转载 作者:太空宇宙 更新时间:2023-11-04 07:11:39 24 4
gpt4 key购买 nike

有什么办法可以简化下面的代码:

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)

关于Python None 变量用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com