python 2.7 - invalid literal for int() with base 10: '16:00:00' -


dic = dict() open('c:\\users\\aman\\documents\\dataval.txt', 'r') fh:     l in fh.readlines():         try:             lines = l.split()             date, sub, num = lines[0], lines[1], [int(x) x in lines[2:]]             dic.setdefault(date, {})             dic[date][sub] = num         except exception er:             print er print dic 

can help? giving me error saying invalid literal int() base 10: '16:00:00' .how rid of it? information '16:00:00' first column in table in txt file

16:00:00     maths   100  95  65  32  23  45  77  54  78  88  45  67  89 17:00:00    science 45   53  76  78  54  78  34  99  55  100 45  56 78 18:00:00  english 43   45  56  76  98  34  65  34  45  67  76  34  98 

i changed int(x) str(x), please try. if thats error.

dic = dict() open('c:\\users\\aman\\documents\\dataval.txt', 'r') fh:     l in fh.readlines():         try:             lines = l.split()             date, sub, num = lines[0], lines[1], [str(x) x in lines[2:]]             dic.setdefault(date, {})             dic[date][sub] = num         except exception er:             print er print dic 

output:

 {'17:00:00': {'science': ['45', '53', '76', '78', '54', '78', '34', '99', '55', '100', '45', '56', '78']},    '18:00:00': {'english': ['43', '45', '56', '76', '98', '34', '65', '34', '45', '67', '76', '34', '98']},    '16:00:00': {'maths': ['100', '95', '65', '32', '23', '45', '77', '54', '78', '88', '45', '67', '89']}} 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -