convert string number to real number - ValueError: invalid literal for int() with base 10: '"2"'
tjreedy at udel.edu
Fri Feb 29 23:26:39 CET 2008
"davidj411" <davidj411 at gmail.com> wrote in message
news:3ca86e1d-a32f-48f2-bc9a-6cb792c0c631 at z17g2000hsg.googlegroups.com...
|i am parsing a cell phone bill to get a list of all numbers and the
| total talktime spend on each number.
| i already have a unique list of the phone numbers.
| now i must go through the list of numbers and add up the totals for
| each number.
| here is the function i wrote to get one number at a time's total
| def getsinglenumbertalktime(number,talktime):
| for line in file[0:-2]:
| | talktime = talktime + li
| return talktime
It would appear that you are calling this function and rescanning scanning
file for each number. It would be more efficient to scan the file once,
for each line parsing out the number and minutes and incrementing the
minutes for that number.
Also, if you had printed repr(li) and len(li) instead of or in
addition to just li (which prints str(li),
>>> print a, repr(a), len(a)
"2" '"2"' 3
you might have seen for yourself the problem that the string contains quote
marks and not just digits. Repr and len are useful debugging aids.
More information about the Python-list