Python错误:扫描字符串文字时出现EOL



一些背景信息

我正在使用SQLite访问数据库并检索所需的信息。我在Python 2.6版本中使用ElementTree来创建一个包含这些信息的XML文件。

代码

以下是我用来从数据库模式创建XML文件的代码。我已经用注释指出了错误发生的位置。

 import sqlite3
 import xml.etree.ElementTree as ET
 db = sqlite3.connect("dataload.db")
 root = ET.Element("databaseConfiguration")

 software_attributes =  ["id", "functionalDesignationHardware", "hwfin", "identname", "partnumber",
                         "repfin", "targetHardwareID"]
 software = db.cursor().execute("SELECT %s from SOFTWARE_" % ", ".join([i + "_" for i in software_attributes]))
 software_Data = software.fetchall()
 for sw in software_Data:
     sw_node = ET.SubElement(root, "Software")
     for i in range(1, len(software_attributes)):
         sw_node.set(software_attributes[i], str(sw[i]))

 target_attributes = ["id", "functionalDesignationSoftware", "installscriptpathname", "ata", "status",
                      "swfin", "targetOSFC", "timestamp"]

 tree = ET.ElementTree(root)
 from xml.dom import minidom
 print minidom.parseString(ET.tostring(root)).toprettyxml(indent = "   ")
 ## The error pops up at this line (when trying to generate the XML) ##
 tree.write("New_Database.xml)

问题

如何修复此错误?我看到了一些其他必须添加或编辑引号的问题——我需要做类似的事情吗,以及如何做?

我之前没有注意到您在标题中放入了错误消息(扫描字符串文字时的EOL)。所以,我认为你的帖子中有一个错别字,这才是真正的错误。将右引号添加到字符串中。

最新更新