我有以下字符串:
monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
和以下 Python 脚本:
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
当我执行脚本时,控制台上显示以下错误消息:
ValueError: 'end_date' is not in list
但是,如果我查找 start_date 的索引,它会正常执行,并返回正确的结果。这是在 Windows 7 x64 上使用 Python 2.7。有什么想法吗?