这是我的csv文件
Dude, 1/1/2011, Brown, Jack Russell
Oogie, 1/1/2006, Grey, Fluffy
Big Bird, 10/11/1969, Yellow, Canary
Garfield, 1/1/1978, Orange, Tabby
这是我的课程:狗
class Dog():
myclass = "Dog"
def __init__(self, name, dob, colour, breed):
self.name = name
self.dob = dob
self.colour = colour
self.breed = breed
def printit(self):
print('Class: ', self.myclass)
print('Name: ', self.name)
print('DOB: ', self.dob)
print('Colour: ', self.colour)
print('Breed: ', self.breed)
我尝试执行此操作,但出现错误“ ValueError:没有足够的值要解压(预期4,得到1)”
我搜索了此错误,但是他们告诉了它有关命令行参数的信息(我认为这对我来说不是问题)
是python的新手,希望您能提供帮助
from animals import *
csv = []
fileobj = open("animals.csv", "r")
for line in fileobj:
row = line.split(",")
name, dob, colour, breed = [i.strip() for i in row]
dog = Dog(name, dob, colour, breed)
csv = csv + [ dog ]
fileobj.close()