I have a function that creates classes derived from it's arguments:
def factory(BaseClass) :
class NewClass(BaseClass) : pass
return NewClass
Now when I use it to create new classes, the classes are all named the same, and the instances look like they have the same type:
NewA = factory(ClassA)
NewB = factory(ClassB)
print type(NewA()) # <class __main__.NewClass>
print type(NewB()) # <class __main__.NewClass>
Is the proper fix to manually set the __name__
attribute?
NewA.__name__ = 'NewA'
print type(NewA()) # <class __main__.NewA>
Are there any other things I should be setting while I'm at it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…