View Full Version : [SOLVED] Python Question on Dictionaries and Classes

July 27th, 2010, 06:22 AM
Hello all! I am having trouble removing and manipulating keys and enumerators I put into my dictionary files(for use other places in the program). Do I have to iterate over them and if so how? I'm still a little fuzzy on how it could help or what the code would look like. I also am assuming that the process is the same as it would be if I were trying to do the same thing from a class I create.

character = {'Inventory':{},'strength':10 , 'dexterity':10 , 'iq':10 ,'name':'Bingo'}

Name2 = character[name]

Why doesn't this work for me?

This is not a homework assignment it is my own personal project, so feel free to help. :)

thanks in advance,


July 27th, 2010, 06:42 AM

July 27th, 2010, 06:52 AM
The issue is that you're trying to access by a nonexistant variable name, when you want to access it with a string.

# wrong

# right

Also, from what I can see, you'd be much better off implementing a Character class than passing around dictionaries.

July 27th, 2010, 05:46 PM
Ooops, lol thanks a lot that was killing me!