python · Summary

Python: OverflowError: signed char is greater than maximum

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

QQ

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

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

Reason: Data from the file should not in a range which from -127 to -1.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s