I have some code that processes some input text by splitting it up:
text = get_data_from_internet() # or read it from a file, whatever
a, b, c = text.split('|')
Usually, this works fine, but occasionally I will get an error message that looks like
ValueError: not enough values to unpack (expected 3, got 1)
If I instead try to get a single result from the split, like so:
first = text.split()[0]
then similarly it seems to work sometimes, but other times I get
IndexError: list index out of range
What is going on? I assume it has something to do with the data, but how can I understand the problem and fix it?
This question is intended as a canonical for common debugging questions. It is meant to explain primarily what the error message means and specifically what about the input string causes the problem. Questions like this are usually not caused by a typo; they are asked by people who need something explained.