convert string number to real number - ValueError: invalid literal for int() with base 10: '"2"'

Terry Reedy tjreedy at udel.edu
Fri Feb 29 17:26:39 EST 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
| talktime.
|
| def getsinglenumbertalktime(number,talktime):
|  for line in file[0:-2]:
...
| | talktime = talktime + li[5]
| 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[5]) and len(li[5]) instead of or in 
addition to just li[5] (which prints str(li[5]),

>>> a='"2"'
>>> 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.

tjr






More information about the Python-list mailing list