gpt4 book ai didi

python - 有没有更好的方法来初始化这个类? Python

转载 作者:行者123 更新时间:2023-12-01 23:28:56 24 4
gpt4 key购买 nike

<分区>

我从数据库中传入一行,该行作为元组读入。我喜欢让所有子类都可以随时使用这些属性的想法,但这感觉好像不需要那么多行就可以完成。有没有更好的方法?

class Player():
def __init__(self, player_attributes):
self.player_id = player_attributes[0]
self.player_first_name = player_attributes[1]
self.player_last_name = player_attributes[2]
self.player_date_of_birth = player_attributes[3]
self.player_city_of_birth = player_attributes[4]
self.player_state_of_birth = player_attributes[5]
self.player_height = player_attributes[6]
self.player_weight = player_attributes[7]
self.player_age = player_attributes[8]
self.player_hair_color = player_attributes[9]
self.player_favorite_food = player_attributes[10]
self.player_favorite_sport = player_attributes[11]
...(20 more attributes)

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