Python 'str' object has no attribute 'name' when using a function variable to call a class instance
<p>I'm just starting to learn programming with python. I'm trying to make a game similar to Pokemon, and I'm trying to apply OOP into agame.</p>

<p>I started by making a Pokemon class, and adding class-defined attributes such as name, HP, etype, attacks. "attacks" is a dictionary of lists.</p>

<p>My problem now is I'm trying to develop a simple battle engine where I can switch out pokemons. For this reason, I made a function/method name fight(). </p>

<p>Inside that I have a variable named current_pokemon.name so whenever I switch out the pokemon, I can use the new pokemon's name, attacks, etc.</p>

<p>I used raw_input to return a string that replaces current_pokemon, which has a .name attribute to call on a pikachu instance. Instead, I get the 'str' object has no attribute. Why doesn't this work? It worked outside the function fight() when I explicitly wrote pikachu.attribute.</p>

<pre><code>class Pokemon(object):
    def __init__(self, name, HP, etype, attacks):
        self.name = name
        self.HP = HP
        self.etype = etype
        self.attacks = attacks #2 attacks with name, dmg, type and power points

geodude = Pokemon("Geodude", 100, "Ground", 
                  attacks = 
                  {"Tackle":["Tackle",30,"Normal","35"], 
                   "Rollout":["Rollout",50,"Rock","20"]
                  })
                    #attacks = {attack:[attack_name, dmg, type, PP]}

pikachu = Pokemon("Pikachu", 100, "Lightning", 
                  attacks = 
                  {"Thunder Shock":["Thunder Shock",40,"Electric"],
                   "Quick Attack":["Quick Attack",40,"Normal"]
                  })

#selects pikachu's attack
print "Pokemon's name is", (pikachu.name)
print "Pikachu's %s attack damages %d" % ((pikachu.attacks["Thunder Shock"][0]),(pikachu.attacks["Thunder Shock"][1]))

pikachu.HP = pikachu.HP - geodude.attacks["Rollout"][1]
print "Pikachu's HP is", (pikachu.HP)
pikachu.HP = pikachu.HP - geodude.attacks["Tackle"][1]
print "Pikachu's HP is", (pikachu.HP)

#Pokemon Battle test with stored variable
#Value selector - replace all var attributes using an easy function
#Use Solution 2

def fight():
    current_pokemon = raw_input("pikachu or geodude? &gt; ")
    print current_pokemon.name
    print current_pokemon.attacks


fight()
</code></pre>

<p>Output:</p>

<pre><code>Pokemon's name is Pikachu
Pikachu's Thunder Shock attack damages 40
Pikachu's HP is 50
Pikachu's HP is 20
pikachu or geodude? &gt; pikachu
Traceback (most recent call last):
  File "poke_game_stack.py", line 40, in &lt;module&gt;
    fight()
  File "poke_game_stack.py", line 36, in fight
    print current_pokemon.name
AttributeError: 'str' object has no attribute 'name'
</code></pre>

<p>Please help noob me with this simple problem!
Thanks!</p>