这里是我的代码:不能打印个别字符串random.choice,只有单个字符
import xml.etree.ElementTree as ET
import random
tree = ET.parse('news.xml')
root = tree.getroot()
channel = root.find('channel')
for item in channel.findall('item'):
title = item.find('title').text
description = item.find('description').text
link = item.find('link').text
print random.choice(title)
这打印出每个标题的对象一个随机字符。我想打印出一个完整的标题字符串。这是原来的XML文件:http://www.11alive.com/rss/local/3/10.xml
把所有的冠军,在列表和'random.choice'列表。 – Volatility 2013-02-24 10:23:07
在你的for循环中,当你打印random.choice(title)''title'变量只有1个标题时,你需要做的是将所有的标题附加到列表中,并且在for循环结束时, '随机打印,选择(随机)' – avasal 2013-02-24 10:23:26