psychopy.org | Reference | Downloads | Github

TypeError: a bytes-like object is required, not 'str'

Hi all,

I am trying to run a task and the same error constantly appears.
In this case the problem occurs when the columns are created in the output file.

outputFile.write (outStr + “\ n”)
TypeError: a bytes-like object is required, not 'str’

If anyone has any ideas, I will really appreciate it.
Thanks in advance!

Are you running a lab based study, which you wrote in the coder interface?
Could you show us the definition of ouputFile?
If I had to guess, I would say that you opened a file in binary write mode with a line like this:

outputFile = open('myfile.csv','wb')

Does the error disappear if you leave out the b?

outputFile = open('myfile.csv','w')

Is there a particular reason for using the write() method instead of methods provided by the csv or the pandas library? I find that they make writing data to a file at the end of an experiment much more convenient.