在python中读取.csv文件时出错

时间:2017-11-13 19:44:29

标签: python-3.x csv file-handling

def __init__(self):
        self.aBasePath = os.getcwd()
        self.DataStorePath = self.aBasePath+"/Data.csv"
        try:
            self.fileDataSet=open(self.DataStorePath)
            print("Opened training dataset.")
        except:
            print("Unable to open training dataset.")
            self.fileDataSet = None

def readFile(self, filePointer=None):
        if filePointer is None:
            filePointer = self.fileDataSet

        try:
            count=0
            print("Started to read")
            with filePointer as f:
               for line in f:
                  print("Started to read")
                  if count==0:
                    print("Started to read")
                    count+=1
                    continue
                  print("Started to read")
                  print(line)

            filePointer.close()
        except:
            print("Unable to read")

错误:

  

打开培训数据集。
开始阅读<无法阅读

上面的代码适用于15行数据,但如果输入中的行数增加,则会出现给定的错误。任何帮助将不胜感激。

0 个答案:

没有答案