My question is how to create variables "on the fly". I'm trying to generate an object with a random set of attributes.
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)
I'm positive how I'm wanting to do this is not a good way, so if anyone understand what I'm looking for and can offer a better method (one that works, for starters) I would be most appreciative.