Search code examples
xmlsqlitepython-2.6elementtreeeol

Python error: EOL while scanning string literal


Some background information

I am using SQLite to access a database and retrieve the desired information. I'm using ElementTree in Python version 2.6 to create an XML file with that information.

Code

Here is the code I'm using to create an XML file from the database schema. I've denoted the location the error occurs with a comment.

 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)

Question

How do I fix this error? I've seen some other questions where quotes had to be added or edited - do I need to do something similar, and how?


Solution

  • I didn't notice before that you had put the error message (EOL while scanning string literal) in the title. So, what I thought was a typo in your post is really the error. Add the closing quote to your string.