在我的python代碼中,我試圖以XML格式顯示輸出。爲此,我使用了XMLwriter
。ImportError:No module named elementtree.SimpleXMLWriter
但它顯示錯誤:
Traceback (most recent call last):
File "C:\Users\Ponmani\Desktop\test.cgi", line 8, in <module>
from elementtree.SimpleXMLWriter import XMLWriter
ImportError: No module named elementtree.SimpleXMLWriter
這會導致錯誤的代碼行是:
from elementtree.SimpleXMLWriter import XMLWriter
我的整個Python代碼是:
import os
import cgi
import MySQLdb
import cgitb
from xml.etree.ElementTree import ElementTree
from elementtree.SimpleXMLWriter import XMLWriter
import sys
import SecureDb
cgitb.enable()
print "Content-type: text/xml\n\n";
root=xml.start("root")
conn= MySQLdb.connect(host = SecureDb.host ,user =SecureDb.user ,passwd=SecureDb.password ,db=SecureDb.database)
cursor=conn.cursor()
xml=XMLWriter(sys.stdout)
cursor.execute("select * from register where Name='Subburaj'")
result=cursor.fetchall()
if(result!=()):
for colns in result:
xml.start("Group")
xml.element("Name","%s" %(colns[0]))
xml.element("Mail","%s" %(colns[1]))
print result
xml.end()
xml.close(root)
conn.commit()
cursor.close()
conn.close()
你需要安裝[elementtree工具包](http://effbot.org/zone/xml-writer.htm)我估計。 – tuxuday
是在您的環境中安裝的''elementtree''模塊? –
你正在使用哪個版本的python?此錯誤表明您沒有安裝元件樹。這是哪個操作系統? – Oz123