2

Many posts that considered there's no difference between wb and w in Unix environments, e.g. Python file IO 'w' vs 'wb' [duplicate]. But mine works the opposite.

The environment is Ubuntu 16.04 and Python 2.7.13. Executing the following code

from __future__ import print_function

log = open("output.txt", "w")
print('{:02d} {} {} {} {} {}'.format(
                queryID,
                "Q0",
                match[0], # filename
                rank,
                match[1], # score
                config.MY_NAME
            ), file = log)

Got error:

TypeError: write() argument 1 must be unicode, not str

Then I tried to replace with wb, problem solved, no more error

log = open("output.txt", "wb")

Could anyone help explain what's going on here?

GabrielChu
  • 6,026
  • 10
  • 27
  • 42

0 Answers0