with open(st) as file:
for line in file:
line = line.rstrip()
name, species, homeworld = line.split("\t")
characters.append(StarWarsCharacter(name, species, homeworld))
I’m trying to extract data, but I just get a value error:
ValueError:
name, species, homeworld = line.split("\t")
ValueError: not enough values to unpack (expected 3, got 1)
>Solution :
First of all, the name of the file should be a string, the it should be "st". Second, the error is clear: it means that the split returns only one token, but you expected 3. Then, the file you are trying to read is not separated by "\t". In fact, trying to reproduce:
script.py:
with open("st") as file:
for line in file:
line = line.rstrip()
ame, species, homeworld = line.split("\t")
Note that i didnt include the last line because I don’t have these structs.
st:
pluto dog homeworld
Running the command python script.py i don’t have any error, because my file is correctly separated by "\t".