#This is the class class ConvertCSVToJSON:     def __init__(self, headings, ID, linesFromFile, inputFileName, outputFileName="Project7Output.txt"):         self.headings=headings  # Headings (row 1 of the file)         self.ID=ID         self.linesFromFile=linesFromFile # rows2-end of file (EOF)         self.outputFileName=outputFileName         self.inputFileName=inputFileName     def createKeyValuePair(self, key, value): # Think about parameters and how the code will work         result="\""+key+"\""+":"+value         return result #create a line function/method in class to have access to headings and file.​ def createLine(self, ID, line):  #splits the line into different components     lineComponets=line.split(",")     dictionary={}#creats a dictionary for the componets     for i in range(len(self.heading)):         dictionary[self.headings[i]]=lineComponents[i]     #adds ID as a keyvalue pair     dictionary["ID"]=str(ID)     #should convert to json     jsonLine="{" + ",".join([self.createKeyValuePair(key, "\"" + value + "\"") for key, value in dictionary. items()]) + "}"     return jsonLine # Main function def main():     headings=["last Name", "First Name"]     ID=1     inputFileName="Input1.txt"     linesFromFile=["Sue", "Lou"]     #objects used to call methods     example1=ConvertCSVToJSON(headings, ID, linesFromFile, inputFileName)     example2=ConvertCSVToJSON(headings, ID, linesFromFile, inputFileName, "Output.txt")     returnedValue=example1.createKeyValuePair("Last Name", "Sue")     print(returnedValue)     #calls my createline method     example1.headings=("First Name", "Last Name", "Age")     example1.linesFromFile=("Sam,Jackson,24", "Tanya,Louis,52")     for line in example1.linesFromFile:         jsonLine = example1.createLine(line)         print(jsonLine) if(__name__=="__main__"):     main() I need to convert this from cvs to json without importing json

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I'm not sure how to fix my error

import csv

#This is the class
class ConvertCSVToJSON:
    def __init__(self, headings, ID, linesFromFile, inputFileName, outputFileName="Project7Output.txt"):
        self.headings=headings  # Headings (row 1 of the file)
        self.ID=ID
        self.linesFromFile=linesFromFile # rows2-end of file (EOF)
        self.outputFileName=outputFileName
        self.inputFileName=inputFileName

    def createKeyValuePair(self, key, value): # Think about parameters and how the code will work
        result="\""+key+"\""+":"+value

        return result

#create a line function/method in class to have access to headings and file.​

def createLine(self, ID, line):  #splits the line into different components
    lineComponets=line.split(",")
    dictionary={}#creats a dictionary for the componets

    for i in range(len(self.heading)):
        dictionary[self.headings[i]]=lineComponents[i]
    #adds ID as a keyvalue pair
    dictionary["ID"]=str(ID)
    #should convert to json
    jsonLine="{" + ",".join([self.createKeyValuePair(key, "\"" + value + "\"") for key, value in dictionary. items()]) + "}"
    return jsonLine

# Main function
def main():
    headings=["last Name", "First Name"]
    ID=1
    inputFileName="Input1.txt"
    linesFromFile=["Sue", "Lou"]
    #objects used to call methods
    example1=ConvertCSVToJSON(headings, ID, linesFromFile, inputFileName)
    example2=ConvertCSVToJSON(headings, ID, linesFromFile, inputFileName, "Output.txt")
    returnedValue=example1.createKeyValuePair("Last Name", "Sue")
    print(returnedValue)

    #calls my createline method
    example1.headings=("First Name", "Last Name", "Age")
    example1.linesFromFile=("Sam,Jackson,24", "Tanya,Louis,52")
    for line in example1.linesFromFile:
        jsonLine = example1.createLine(line)
        print(jsonLine)

if(__name__=="__main__"):
    main()

I need to convert this from cvs to json without importing json

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education