python mysql 导出到文本的有关问题

python mysql 导出到文本的问题
大家好,
我怎么写才能把select后的所有结果导出到txt中。

# -*- coding: utf-8 -*-
import MySQLdb
conn = MySQLdb.connect(host='localhost',db='test',user='abc',passwd='abc')
cur = conn.cursor()
cur.execute('SELECT * FROM test limit 10;')
for r in cur.fetchall():
    text = r[0]
    print text
    f = file('text.txt', 'w')
    f.write(str(text))
    f.close() 
conn.close()

现在只能导出最后一行。 多谢了!
python mysql 

------解决方案--------------------
引用:
引用:Python code?123456789101112131415161718192021222324# -*- coding: utf-8 -*- import MySQLdb conn = MySQLdb.connect(host='localhost',db='test',user='abc',passwd='abc')cu……

嗯,写迷糊了,本意是写一个function的