with open(path, 'wb') as csv_file:
csv_write = csv.writer(csv_file)
csv_head = ["A", "B"]
csv_write.writerow(csv_head)
运行错误提示:
TypeError: a bytes-like object is required, not ‘str’
Python 3. csv采用文本模式输入,不是二进制模式,不能用wb
解决方案:
with open(path, 'w') as csv_file:
csv_write = csv.writer(csv_file)
csv_head = ["A", "B"]
csv_write.writerow(csv_head)