Advertisement
MrFriday

Random Trait String function

Sep 12th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1.  
  2. def rts(girl, options):
  3.     """
  4.    Get a random string from a random trait that a girl has.
  5.    girl = The girl to check the traits against.
  6.    options = A dictionary of trait/eval -> (strings,).
  7.    """
  8.     default = options.pop("default", None)
  9.     available = list()
  10.    
  11.     for trait in options.iterkeys():
  12.         if trait in traits:
  13.             if trait in girl.traits: available.append(options[trait])
  14.        
  15.         else:
  16.             if eval(trait, globals(), locals()): available.append(options[trait])
  17.    
  18.     if len(available) == 0: trait = default
  19.     else: trait = choice(available)
  20.    
  21.     if isinstance(trait, (list, tuple)): return choice(trait)
  22.     else: return trait
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement