NoneType and new instances

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jul 29 03:20:59 CEST 2011


Ian Kelly wrote:

> Why would you ever need to instantiate NoneType?


Well, you probably wouldn't deliberately, but if you have code like this:


types = [type(x) for x in list_of_objects]
# later on...
for t in types:
    instance = t()
    do_something_with(instance)


it would be nice if it didn't explode when list_of_objects contains None.


-- 
Steven




More information about the Python-list mailing list