【发布时间】:2012-01-30 04:00:55
【问题描述】:
我的 csv 文件如下所示:
artist,year,id,video_name,new_video_id,file_root_name,video_type
,,,,,,
Clay Aiken,1,clay_aiken,Sorry Seems To Be...,sorry-seems-to-be,02_sc_ca_sorry,FLV
Clay Aiken,1,clay_aiken,Everything I Do (I Do It For You),everything-i-do-i-do-it-for-you,03_sc_ca_everything,FLV
Clay Aiken,1,clay_aiken,A Thousand Days,a-thousand-days,04_sc_ca_thousandda,FLV
Clay Aiken,1,clay_aiken,Here You Come Again,here-you-come-again,05_sc_ca_hereyoucom,FLV
Clay Aiken,1,clay_aiken,Interview,interview,06_sc_ca_intv,FLV
上面的每一行都会生成一个单独的 xml 文件,如下所示(准确地说是 5 个):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE smil PUBLIC "-//W3C//DTD SMIL 2.0//EN" "http://www.w3.org/2001/SMIL20/SMIL20.dtd">
<smil xmlns="http://www.w3.org/2001/SMIL20/Language">
<head>
<meta base="rtmp://cp23636.edgefcs.net/ondemand" />
</head>
<body>
<switch>
<video src="mp4:soundcheck/%year/%id/%file_root_name_256.mp4" system-bitrate="336000"/>
<video src="mp4:soundcheck/%year/%id/%file_root_name_512.mp4" system-bitrate="592000"/>
<video src="mp4:soundcheck/%year/%id/%file_root_name_768.mp4" system-bitrate="848000"/>
<video src="mp4:soundcheck/%year/%id/%file_root_name_1128.mp4" system-bitrate="1208000"/>
</switch>
</body>
</smil>
将其命名为 %new_video_id.smil
我已经弄清楚如何解析 csv 文件:
import csv
import sys
f = open(sys.argv[1], 'rU')
reader = csv.reader(f)
for row in reader:
year = row[1]
id = row[2]
file_root_name = row[5]
print year, id, file_root_name
如何在编写 xml 文件时获取每个变量并包含?
【问题讨论】:
-
为什么在遍历 csv 时不构建 xml?
-
不是一个xml,每一行都是一个新的xml。
-
您需要在内存中构建它还是将每个 xml 文件保存到磁盘?
-
@DavidNeudorfer 你的意思是每行都是
video单个xml文件中的标签? -
每一行都将是一个写入磁盘的新 xml 文件。每个文件将使用
new_video_id变量命名