私の質問は、「その場で」変数を作成する方法です。ランダムな属性セットを持つオブジェクトを生成しようとしています。
from random import randint, choice
class Person(object):
def __init__(self):
self.attributes = []
possible_attributes= ['small', 'black', 'scary', 'smelly', 'happy'] # idk, random
chance = randint(1,5)
chosen_attributes = []
for i in xrange(chance):
#psuedo code...
local_var = choice(possible_attributes)
if local_var not in chosen_attributes:
VAR = local_var # VAR needs to be dynamic and 'global' for use later on
chosen_attributes.append(local_var)
Person.attributes.append(local_var)
私がこれをやりたいと思っているのは良い方法ではないので、誰かが私が探しているものを理解し、より良い方法(初心者にとってはうまくいく方法)を提供できるなら、私は最も感謝しています.