これに似たコードをいくつか取得しました。正確ではありませんが、あまり言いませんが、check_typeがr_typeパラメータを文字列として受け入れ、オブジェクト タイプがこの文字列の値であるかどうかを確認する必要があります。それは実行可能ですか?!?!?
繰り返しますが、それはできません: n.check_type(r_type=Newer)* 、構成ファイルからr_type値を取得する必要があり、その方法は文字列です!
class New(object):
def check_type(self, r_type):
print 'is instance of r_type: ', isinstance(self, r_type)
return isinstance(self, r_type)
class Newer(New):
pass
if __name__ == '__main__':
n = Newer()
n.check_type(r_type='Newer')
出力:
print 'is instance of r_type: ', isinstance(self, r_type)
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types