OverflowError: signed char is greater than maximum

Posted on June 6, 2017

Here the pseudo code about the flow:

from array import array
c = array('b')
with open(file, mode = 'rb') as f:
    for character in f:
        res = func(character)
        c.append(res)

It runs into the error:

OverflowError: signed char is greater than maximum

with a special character ‘À’ which its binary value is 192:

Character
Character

My way to resolve this error is to update the type code of the array from ‘b’ (signed char) to ‘B’ (unsigned char).

from array import array
c = array('B')

Reason: Data from the file will not in the range: from -127 to -1.


OverflowError: signed char is greater than maximum


donation

Scan the QR code using WeChat

comments powered by Disqus