def codepoint_count():
    testlength = len('\U00010000')
assert testlength == 1 or testlength == 2
if testlength == 1:

    def closure(data):
        'returns the number of Unicode code points in a unicode string'
return len(data.encode('UTF-16BE').decode('UTF-16BE'))
How to get a reliable unicode character count in Python?