Question: I have the following string:

```
monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date

```

and the following Python script:

```
from datetime import datetime, date, time
today = datetime.now()
print today

print today
with open('calendar_clean.txt', 'w') as f1:
    with open('calendar.txt', 'r') as f:       
        newline = ""
        end_date_index = -1       
        for line in f:
            items = line.split(",")

            if end_date_index == -1:
                for item in items:
                    print item
                print "finding end_date index"
                end_date_index = items.index('end_date')
                print end_date_index

```

When I execute script, the following error message is displayed on the console:

```
ValueError: 'end_date' is not in list

```

If I look for the index of start\_date, however, it executes normally, returning correct result. This is using Python 2.7 on Windows 7 x64. Any ideas out there?

Answer: 
You have a line terminator on the end of your line. So it's looking for something like "end\_date\n" or "end\_date\r", not just "end\_date". Use `line.rstrip().split(",")` instead of only calling `split`.
Since you're reading the data from the file, the line probably has a newline (`\n`) at the end of it. This means the last item is not `"end_date"` but `"end_date\n"`. Try doing `items = line.strip().split(",")` to remove the trailing whitespace.