In Python you can use the globals function to get a dictionary of variable names : values. But allowing user input in this scenario is too much of a security risk; rather, I'd advise you to create a nations dictionary, like so:
nationalities = {
'canadian' : ["Gordy", "Gordon", "Gord"],
'american' : ["Bob", "Bill", "Bush"]
}
and then you could simply do stuff like
nation = raw_input("Please enter the region: ")
if nation.lower() not in nationalities:
....
names = nationalities[nation.lower()]
man = Naming(names)
but then, I don't see a point in using the Naming class, but I guess that you're just doing this as an exercise.
Name:
Anonymous2010-08-25 12:21
Thanks #3, I'm pretty sure that will work.
You're right that it's an exercise. The coded I posted there was just an example. The actual script is for a full character generation thingy for a corporate espionage strategy game, so the "name" will just be one aspect of the class as a whole. Since I want to be able to specify the ethnicity of a character (as well as just make 'random') in the class's __init__, I was worried I'd need potentially hundreds of if/elif statements to match the user's inputed ethnicity to the write grouping of names.
Saw this thread on /g/ an hour ago or so, everyone there were trying to sound like an expert and said ``Yeah definitely use raw_input, input is unsafe as it tries to run the command the user inputs'' instead of reading the OP.
OP here. I refreshed the /g/ thread for a few minutes, and it seemed no one was posting so I figured I'd try here. I probably should have clarified that I'm using Python 3.1, but I figured that would have been obvious to anyone who knows Python and saw the print() statement; I started working with 2.7, so I know the difference between raw_input() and input() in the two.