I got this text in a text file file:
_2015.9.30 - 15:36:3 , 13_
_2015.9.30 - 15:36:6 , 24_
_2015.9.30 - 15:36:8 , 33_
and I want to have it like this
_data=['2015.9.30 - 15:36:3', '2015.9.30 - 15:36:6', '2015.9.30 -15:36:8']_
_values=['13', '24', '33']_
so I tried this code
def getData(path):
data = []
readFile = open(path,'r')
sepFile = readFile.read().split('\n')
readFile.close()
for i in sepFile:
myData = i.split(',')
data.append(myData[0])
return data
def getValues (path):
values = []
readFile = open(path,'r')
sepFile = readFile.read().split('\n')
readFile.close()
for i in sepFile:
myValues = i.split(',')
values.append(myValues[1])
return values
print getData("mytext.txt")
print getValues("mytext.txt")
the first method getData works fine but the second one dont want to work .. errormessage:
['2015.9.30 - 15:36:3 ', '2015.9.30 - 15:36:6 ', '2015.9.30 - 15:36:8']
Traceback (most recent call last):
File "C:\Python27\z.NEW\schrottplatz.py", line 34, in <module>
print getValues("mytext.txt")
File "C:\Python27\z.NEW\schrottplatz.py", line 29, in getValues
values.append(myValues[1])
IndexError: list index out of range
_really part of your data?