xml:每2次写入文件

时间:2018-08-04 09:46:58

标签: xml python-2.7 loops

我有以下python脚本将数据存储存储为xml文件:

f=open('/Users/tests/test1/FileList_2013a.dat','w')
tree = xml.etree.ElementTree.fromstring( result )
for g in tree.getiterator("Granule"):
    print g.attrib['name']
    if options.url != None:
        for u in g.getiterator("Url"):
            if u.attrib.has_key('extensions') and u.attrib["extensions"] != "":
                print "%s.%s" % (u.attrib["url"], u.attrib["extensions"])
            else:
                print u.attrib["url"]
                f.write(u.attrib["url"] + '\n')

如何每2次写入文件一次?

谢谢!

João

0 个答案:

没有答案