这是代码示例:
import csv
file = open("countries_information.csv", 'wb')
writer = csv.writer(file)
writer.writerow(['Country Name'.encode("utf-8)])
我收到错误
"TypeError: a bytes-like object is required, not 'str'"
我在网上浏览了解决方案,但我很茫然。
为什么在打开文件时不指定格式?喜欢:
import csv
file = open("countries_information.csv", 'w', encoding='utf-8')
writer = csv.writer(file)
writer.writerow(['Country Name'])