Error in class type judgment(Exception):
def __init__(self,ideal,reality): super(Exception, self).__init__(str(ideal)+'Even though the shape was good'+str(reality)+'The mold was passed')
class type is:
def __init__(self,Mold): self.Mold=Mold
Judgment whether it is def(self,instance):
if isinstance(instance, self.Mold): return instance
else:error in raise type judgment(self.Mold.__name__, type(instance).__name__)
Write,
foo = Determine if type is (hoge). (Var)
If you write
It will check if var
is of type hoge
.
If var
is of type hoge
, do nothing,
If it is not of type hoge
, throw an exception.
Error in class type judgment(Exception):
def __init__(self,ideal,reality): super(Exception, self).__init__(str(ideal)+'Even though the shape was good'+str(reality)+'The mold was passed')
class type is:
def __init__(self,Mold): self.Mold=Mold
Judgment whether it is def(self,instance):
if isinstance(instance, self.Mold): return instance
else:error in raise type judgment(self.Mold.__name__, type(instance).__name__)
class dog:
pass
class cat:
pass
def Put on the collar and go outside(Dog):
The type is(dog).Judgment(Dog)
print('It's a walk!')
print("1st");Put on the collar and go outside(dog())
print("2nd");Put on the collar and go outside(Cat())
Is as follows.
1st
It's a walk!
2nd
Traceback (most recent call last):
File "D:\sd_First half of 4 years\First half of 4 years\SUDAP3_-1\cgi-bin\Typer.py", line 19, in <module>
print("2nd");Put on the collar and go outside(Cat())
File "D:\sd_First half of 4 years\First half of 4 years\SUDAP3_-1\cgi-bin\Typer.py", line 15,in Put on the collar and go outside
The type is(dog).Judgment(Dog)
File "D:\sd_First half of 4 years\First half of 4 years\SUDAP3_-1\cgi-bin\Typer.py", line 7,Judgment whether in
else:error in raise type judgment(self.Mold.__name__, type(instance).__name__)
Error in type determination:The dog type was good, but the cat type was handed over
Recommended Posts