Original Post
Hi. I'm using python for a stratego-like game. I've run into a problem which I am sure Python can take care of very easily. I want to take a list of strings and turn them into unit objects. I have a base class called Unit. There are several subclasses such as Marshall, Bomb, Flag, Spy, General, Scout, etc. I also have a list of strings corresponding to those names. Each name appears once for every copy of that unit you start with. So, it looks like:
["General", "Major", "Major", "Major", ... ] Since you start off with 1 general and 3 major units. What I want to do is run through this list and somehow generate the correct type of unit from a string. I would think it would follow the form: for unit in unitNames:
unitClass = ????(unit)
unitList.append(apply(unitClass), ...) Does Python have a function or way to fill in the ???? (a function to convert a string to the class/type that corresponds to that type). Thanks in advance.