Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
convert string number to real number - ValueError: invalid literal
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Terry Reedy, post: 3462008"] |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]), "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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
convert string number to real number - ValueError: invalid literal
Top