Hi, I'm writing a small script to automate some processes for testing purposes.
This is what the relevant part of my code looks like:
def demote_to_user(student_file: str):
with open(student_file) as student_csv:
students = [Student(login, int(matriculation_number), first_name, last_name)
for student_line in student_csv.readlines()[1:]
for login, matriculation_number, _, first_name, last_name in student_line.split(",")]
if __name__ == "__main__":
demote_to_user("single_sample.csv")
```and here's the `single_sample.csv`:
```csv
login,matriculation number,email,firstname,lastname
user_51,00000051,[email protected],Tilda,MΓΌller
This is the error I get:
Traceback (most recent call last):
File "/home/samuel/PycharmProjects/PythonProject/main.py", line 120, in <module>
demote_to_user("single_sample.csv")
File "/home/samuel/PycharmProjects/PythonProject/main.py", line 89, in demote_to_user
for login, matriculation_number, _, first_name, last_name in student_line.split(",")]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 5)
I've ran this version of the code:
def demote_to_user(student_file: str):
with open(student_file) as student_csv:
for student_line in student_csv.readlines()[1:]:
print(student_line)
print(student_line.split(","))
login, matriculation_number, _, first_name, last_name = student_line.split(",")
```and it works without any problems.
Now I know that I could just re-write it with that explicit for-loop, but I really want to keep the list comprehension in there, at this point it's just out of spite π