Lets say 'a' is of some type (which I want to know!)
Doing a thing like:
b = str(a)
This should favorably raise a TypeError
There is no builtin Python class that raises a TypeError with str, but you could define a custom class:
class Foo(object):
def __str__(self):
raise TypeError('Can not by stringified')
foo = Foo()
b = str(foo)
raises a TypeError.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With