I'm trying to read some values from a file, but I keep getting errors when trying to split them up;
The text file looks like this:
2009-10 0:12:01
2009-12 0:06:24
2010-06 0:29:24
2012-06 0:10:29
Here's my code;
myFiles = glob.glob('./*.txt')
for fileName in myFiles:
fileHandle = open(fileName,'r')
print str(fileName)
for date, value in str(fileHandle.readline()).split(' ',1):
print "date: " + str(date)
print "value: " + str(value)
What I want to output:
<filename>
date: 2009-10
value: 0:12:01
date: 2009-12
value: 0:06:24
date: 2010-06
value: 0:29:24
date: 2012-06
value: 0:10:29
<filename>
etc
etc...
The error I'm getting:
Traceback (most recent call last):
File "./scratch.py", line 16, in <module>
for date, value in str(fileHandle.readlines()).split(' ',1):
ValueError: too many values to unpack
str(fileHandle.readline()).split(' ',1), without ans, but your traceback says your real code has one:str(fileHandle.readlines()).split(' ',1).