title: Call an class object with a name that is from user-input
body: <p>Basically, The user creates a creature by giving it a name, this name is then fed into the creation of the creature, where it is then given stats (This all works fine, even when making several creatures). However, I want to give the option to the user to check the stats of the creature they created through the 'check_stats()' function, they do this by inputting the slot number of the creature in their line-up, the code then finds the name of the creature through this, and calls the check_stat function using it. However this does not work as I receive the error:</p>
  <pre><code>AttributeError: 'str' object has no attribute 'check_stats'
  </code></pre>
  <p>If i create the creature manually in the code, like I write:</p>
  <pre><code>Bill = Pet('Bill')
  </code></pre>
  <p>It works perfectly and i can call the stats whenever.
  Its just when the user creates the class instance, it does not work.</p>
  <p>This is my code (That is the problem):</p>
  <pre><code>def create_creature():
      creature = Pet(name)
      creature.create_stats()
      print(&quot; \n \n \n&quot;)
  
  minions = {}
  minion_value = {
      1: None,
      2: None,
      3: None,
      4: None,
      5: None,
      6: None
  }
  
  minion_slot = 0
  for value in range(2):
      name = input(&quot;Create a pet!\n&gt; &quot;)
      minions[name] = create_creature()
      minion_slot += 1
      minion_value.update({minion_slot : name})
  
  
  print(&quot;Your line-up&quot;)
  for creature_ in minion_value:
      print(&quot;{}: {}&quot;.format(creature_, minion_value[creature_]))
  
  check_creature = int(input(&quot;Which pet would you like to check? (number)\n&gt; &quot;))
  for creature_ in minion_value:
      if check_creature == creature_:
                  (minion_value[check_creature]).check_stats()
  </code></pre>
  <p>This is what the output of this code looks like:</p>
  <pre><code>Create a pet!
  &gt; Bob
  ---Bob---
  3 years old 
  5% healthy
  66% happy
  65% crazy
  48% smarts
   
   
   
  
  Create a pet!
  &gt; Bill
  ---Bill---
  9 years old 
  100% healthy
  35% happy
  93% crazy
  13% smarts
   
   
   
  
  Your line-up
  1: Bob
  2: Bill
  3: None
  4: None
  5: None
  6: None
  Which pet would you like to check? (number)
  &gt; 1
  Traceback (most recent call last):
    File &quot;C:\Users\c10ld\Downloads\Test_class_animals.py&quot;, line 103, in &lt;module&gt;
      (minion_value[check_creature]).check_stats()
  AttributeError: 'str' object has no attribute 'check_stats'
  </code></pre>
  <p>This is what it should look like:</p>
  <pre><code>Create a pet!
  &gt; Bob
  ---Bob---
  3 years old 
  5% healthy
  66% happy
  65% crazy
  48% smarts
   
   
   
  
  Create a pet!
  &gt; Bill
  ---Bill---
  9 years old 
  100% healthy
  35% happy
  93% crazy
  13% smarts
   
   
   
  
  Your line-up
  1: Bob
  2: Bill
  3: None
  4: None
  5: None
  6: None
  Which pet would you like to check? (number)
  &gt; 1
  
  Your Pet:
  ---Bob---
  3 years old 
  5% healthy
  66% happy
  65% crazy
  48% smarts
  </code></pre>
  <p>Can anyone help me? Thank you! (Sorry if this is too long, its my first post and i wanted to make sure there was little to no confusion.)</p>
  <p>EDIT:
  Here is the rest of the code, including the Pet class:</p>
  <pre><code>import random
  
  
  
  class Animal(object):
      def __init__(self, age, health, happiness):
          self.age = 0
          self.health = 0
          self.happiness = 0
          
          
      def get_age(self):
          self.age = random.randint(8, 100)
   
      def get_health(self):
          self.health = random.randint(1, 100)
          print(f&quot;{self.health}% healthy&quot;)
       
      def get_happiness(self):
          self.happiness = random.randint(1, 100)
          print(f&quot;{self.happiness}% happy&quot;)
          
      def age_up(self):
          self.age += 1
          print(f&quot;{int(round(self.age, 0))} years old&quot;)
          
          if self.age &lt; 17:    
                  self.age_up()
              
          elif self.age &gt;= 17:
                  print(&quot;died of age.&quot;)
  
  
  
  class Pet(Animal):
      def __init__(self, name):
          self.name = name
          self.craziness = 0
          self.intelligence = 0
      
      
      def pet_age(self):
         self.get_age()
         self.age = self.age / 7
         print(f&quot;{int(round(self.age, 0))} years old &quot;)
         
           
      def get_craziness(self):
          self.craziness = random.randint(1,100)
          print(f&quot;{self.craziness}% crazy&quot;)
          
      def get_intelligence(self):
          self.intelligence = random.randint(1, 100)
          print(f&quot;{self.intelligence}% smarts&quot;)
          
      def create_stats(self):
           print(f&quot;---{self.name}---&quot;)
           self.pet_age()
           self.get_health()
           self.get_happiness()
           self.get_craziness()
           self.get_intelligence()
           
      def check_stats(self):
           print(f&quot;---{self.name}---&quot;)
           print(f&quot;{int(round(self.age, 0))} years old&quot;)
           print(f&quot;{self.health}% healthy&quot;)
           print(f&quot;{self.happiness}% happy&quot;)
           print(f&quot;{self.craziness}% crazy&quot;)
           print(f&quot;{self.intelligence}% smarts&quot;)
  </code></pre>
  <p>I created an 'Animal' class as i was planning on creating more sub-classes, such as workers and warriors!</p>