promotion image of download ymail app
Promoted

Why is my program not working?

How come my dataColumns are not getting filled with the numbers from the file? This is python.

import time

import InputOutputHandler

fileName = input("Enter the .csv file name: ")

fileUse = InputOutputHandler.readCSVFile(fileName)

headers = InputOutputHandler.headerSplitter(fileUse)

rowCount = 0

for row in fileUse:

  rowCount += 1

def main(headers):

   #create a list with header-number of lists in it

   dataColumns = []

   for i in headers:

       dataColumns.append([]) #fills inital list with as many empty lists as there are columns

  #adds a column of data into each empty list

  for row in fileUse:

     comps = row.strip().split(',') #components of data

     for j in range(len(comps)):

        dataColumns[j].append(float(comps[j])) #appends the jth entry into the jth column, separating data into categories

  return dataColumns

def readCSVFile(fileName):

   inputFile = open(fileName)

   return inputFile

def headerSplitter(fileUse):

   headers = fileUse.readline().strip('\n').split(',') #create headers for columns and strips unnecessary characters

   return headers

dataColumns = main(headers)

InputOutputHandler.printCSVFile(dataColumns, headers, rowCount)

1 Answer

Relevance
  • Snezzy
    Lv 7
    2 months ago

    Indents on lines 15 and 19 are wrong.

    My system does not find line 2's InputOutputHandler and I'm not going to bother hunting for it.

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.