python csv写入不完整_python csv写入列而不是行

一个Python脚本示例,原本用于按行写入CSV文件,但需要修改为按列写入。目前,它遍历文件夹并生成包含多个字符串的列表,然后随机选择一个写入CSV。要改为按列写入,需要调整写入方式。
摘要由CSDN通过智能技术生成

我有一个脚本,生成10行,每行在不同的行上。

我希望它生成10列,而不是行。在import csv

import os

import random

for dirname, dirnames, filenames in os.walk(r"C:/Users/s/Desktop/filme/"):

for subdirname in dirnames:

foldere_filme = os.path.join(dirname, subdirname)

numarul_folderelor = foldere_filme.replace("C:/Users/s/Desktop/filme/", "")

print numarul_folderelor #1,2,3,4,5...

root_text = "C:/Users/s/Desktop/text/tags"+numarul_folderelor+".csv"

fisier_text_tags = csv.writer(open(root_text,'wb'))

for filenames in os.listdir(foldere_filme):

tags = filenames.replace("", " ").replace(".avi", "")

test = ['blah '+varible+' test, blah '+varible+' aaaaah clip, blah '+varible+' putlocker, download '+varible+' clip',

'blah '+varible+' free tuttiing, blah '+varible+' clip free, blah '+varible+' test clip, download '+varible+' aaaaah clip',

'blah '+varible+' 2012, blah '+varible+' test free, download '+varible+' 2012 clip, free tuttiing '+varible+'',

'blah '+varible+' free aaaaah clip, blah '+varible+' test 2012, where to blah '+varible+', '+varible+' aaaaah clip test',

'strem '+varible+' test free, blah '+varible+' free 2012, blah '+varible+' test for free, '+varible+' aaaaah clip test',

'putlocker 2012, blah '+varible+' free, download '+varible+' test, blah test '+varible+' for free, free clip tuttiing']

random.shuffle(test)

fisier_text_tags.writerow(test[0:1])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值