Why am I getting an error in Python 'cannot import name NoneType'?

I am trying to convert code from 2 to 3 and the following simple script

import types
from types import NoneType

Results in

ImportError: cannot import name NoneType

How can I convert the above from 2 to 3?

+5
source share
1 answer

The modules typesno longer have a link NoneType. You should simply verify your identity with Nonedirectly, i.e. obj is None. An alternative way, if you really need to NoneType, is to get it with:

NoneType = type(None)

This is actually the same method that was previously defined types.NoneTypebefore it was deleted on November 28, 2007 .

, from .. import, import types, .

+8

All Articles