How do I put a debug statement (like print) in reducer or mapper for mrjob. If I try to use print or sys.stderr.write(), I get an error TypeError: a bytes-like object is required, not 'str'
Asked
Active
Viewed 1,264 times
1 Answers
1
The error message indicates that the output handle is open to a binary stream, not a text stream (the difference between open(filename, 'w')
and open(filename, 'wb')
. Try
sys.stdout.write(message.encode())
If the encoding is not your default encoding, you have to add that explicitly (e.g. message.encoode('utf-8')
).

tripleee
- 175,061
- 34
- 275
- 318