执行下面的代码时,“ BannedList.txt”会生成文件,但是当我检查文件时,每个字符之间都有一个空格:
if type is "Banned":
with open('BannedList.csv', 'r') as f:
# banned_reader = csv.reader(f, delimiter='\t')
result = {(x[4], x[12]) for x in csv.reader(f)}
with open('BannedList.csv', 'r') as f:
banned_reader = csv.reader(f, delimiter=',')
for row in banned_reader:
row = ",".join(row)
self.banned_alt_sku.append(row)
with open('DailyBannedItems.csv') as f:
for row in csv.reader(f):
if(row[0], row[2]) in result:
self.new_rows.append(row[4])
with open('BannedList.txt', 'w', newline='') as output:
writer = csv.writer(output, skipinitialspace=True, delimiter='\t')
# writer.writerows(",".join((x, y)) for x, y in zip(self.banned_alt_sku, self.new_rows))
writer.writerows(",".join((x, y)) for x, y in zip(self.banned_alt_sku, self.new_rows))
我尝试将'r'更改为'rb',但这给了我以下错误:
'iterator should return strings, not bytes (did you open the file in text mode?)'
我该如何解决这个问题?
谢谢