我尝试使用Python 2将集合和格式化字符串的内容写入CSV文件。我有一整套域名,我需要将域名写入第一列,跳过一列,然后写下“相关'”,并在下一行重复,直到该集为空。我尝试了一些不同的东西,但这就是我现在所处的位置(破码)。
#!/usr/bin/python
#CSV WRITE TESTING
import csv
testSet = set(['thissucks.in', 'whateverlife.in', 'crapface.in', 'lasttry.in'])
with open('mag.csv', 'ab+') as f:
writer = csv.writer(f + ' ' + 'Related',dialect= 'excel', delimiter= ',')
for each in testSet:
writer.writerow(list(testSet))
答案 0 :(得分:1)
import csv
testSet = set(['thissucks.in', 'whateverlife.in', 'crapface.in', 'lasttry.in'])
with open('mag.csv', 'ab+') as f:
writer = csv.writer(f ,dialect= 'excel', delimiter= ',')
for domain in testSet:
writer.writerow([domain, '', 'Related'] )