I am trying to take a text file with dates and reformat them. Ex: '1/31/2017' becomes '2017-1-31T:00:00:00Z'
Code:
with open("test.rtf") as f:
data = f.readlines()
for line in data:
a,b,c = line.split("/")
if len(a) < 2:
a = "0" + a
if len(b) <2:
b = "0" + b
print(c,"-",a,"-",b,"T:00:00:Z")
However, it is returning an error: Traceback (most recent call last): File "pubdateformat.py", line 8, in a,b,c = line.split("/") ValueError: need more than 1 value to unpack
Can anyone explain what this is saying?
Thanks for the help!
line.split("/")looks to be returning a list with only 2 items. For what it's worth though, I'd recommending looking into the datetime library to do this for you rather than manually converting strings. In particular, look intostrftimeandstrptime. - thesilkwormdataseems to contain lines with no"/"so split will return just the line. - pask