Checking whether type is None

Chris Angelico rosuav at gmail.com
Sat Jul 28 06:20:17 EDT 2018


On Sat, Jul 28, 2018 at 8:07 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sat, 28 Jul 2018 09:47:07 +0000, Gilmeh Serda wrote:
>
>> On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote:
>>
>>> I'm trying to get away from things like:
>>>
>>>      >>> type(thing) is type(None)
>>
>> How about:
>>
>>     >>> some_thing = None
>>     >>> type(some_thing).__str__(some_thing)
>>     'None'
>>
>> Equally weird, I'd say, but what the heck...
>
> class Foo:
>     def __str__(self):
>         return 'None'

>>> object.__str__(some_thing)

Problem solved. :)

ChrisA



More information about the Python-list mailing list