file为什么最后一个write 得不到数据

file为什么最后一个write 得不到数据



[Copy to clipboard] [ - ]
CODE:
import MySQLdb
from xml.dom.minidom import parse, parseString

connstr = MySQLdb.connect("localhost", "root", "12345", "xoops")
conn = connstr.cursor()
conn.execute("select * from my_art_article")
conn.scroll(0)
filename = "3.xml"
f = file(filename, "a")
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
f.write("<root>")
while(1):
    irows = conn.fetchone()
    if irows == None:
        break
    f = file(filename, "a")
    f.write("<title>"+irows[5]+"</title>")
f = file(filename, "a")
f.write("</root>")
f.close
print "xml create succeed."

xml如下
<?xml version="1.0" encoding="utf-8"?><root><title>All About XOOPS</title><title>What is Open Source software?</title><title>Article Quickstart Guide</title><title>FAQs on Article</title>

写的比较乱,检查下自己解决了,要认真呵呵
f.close貌似掉了括号
而且最好在关闭文件前fflush下