Python错误(ValueError:需要超过0个值来解包)

时间:2014-03-26 21:27:27

标签: python csv python-3.x

我正在检查我的代码并正确加载csv然而当我保存并再次加载它之后它将我的csv用双行

原始csv

  

scp,name,Sporting Clube de Portugal
scp,stadium,Alvalade
...

之后

  

scp,name,Sporting Clube de Portugal

     

SCP,体育场,阿尔瓦拉德

     

...

所以当我尝试再次加载它时会说出错误(ValueError:需要超过0的值才能解压缩)

这是legraph.py

def load(self, filename):
     f = open(filename, "r")
     reader = csv.reader(f)
     for sub, pred, obj in reader:
        self.add(sub, pred, obj)
     print('Done')
     f.close()

def save(self, filename):
     f = open(filename, "w")
     writer = csv.writer(f)
     for sub, pred, obj in self.triples(None, None, None):
        writer.writerow([sub, pred, obj])
     f.close()

这是main.py

   elif opt == "5":
            path = ""
            while path == "":
                path = input("File name (no extension): ")
                if path == "":
                    print ("Specify the name of the file you want to read!")
            path += ".csv"
            lg.load(path)
            wait()

        elif opt == "6":
            path = ""
            while path == "":
                path = input("File name (no extension):")
                if path == "":
                    print ("Please type a name for your file!")
            path += ".csv"
            lg.save(path)
            wait()

错误

Traceback (most recent call last):
  File "C:/Users/PedroVortex/PycharmProjects/Projecto1/Main.py", line 110, in <module>
    lg.load(path)
  File "C:\Users\PedroVortex\PycharmProjects\Projecto1\LeGraph.py", line 167, in load
    for sub, pred, obj in reader:
ValueError: need more than 0 values to unpack

0 个答案:

没有答案