python inheritance: choose parent class using argument
问题 I'm having trouble designing some classes. I want my user to be able to use the Character() class by passing in an argument for the type of character (e.g. fighter/wizard). Dummy code: class CharClass(): def __init__(self, level): self.level = level class Fighter(CharClass): # fighter stuff pass class Wizard(CharClass): # wizard stuff pass class Character(): #? def __init__(self, char_class): # should inherit from Fighter/Wizard depending on the char_class arg pass For example, after calling: