3

I try to port my code from python 2.7 to 3.4. Under 2.7 it works quite well. I will import a Picoscope binary file and get the following error under Python 3.4 (ubuntu):

in __import_CS
data_A = bin_file_A.read(64)
File "/usr/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in position 1: invalid continuation byte

here the code piece:

bin_file_A = open(infile ,"r")
bin_file_B = open(infile_B ,"r")

######  read file header ########
data_A = bin_file_A.read(64)
data_B = bin_file_B.read(64)

start = 0
stop = struct.calcsize('8d')
n_A = struct.unpack('>8d', data_A[start:stop])
n_B = struct.unpack('>8d', data_B[start:stop])

1 Answer 1

4

You need to read the files in binary mode:

bin_file_A = open(infile_A, "rb")
bin_file_B = open(infile_B, "rb")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.