problem moving from char to integer
Larry Bates
larry.bates at websafe.com
Tue Sep 26 19:43:32 EDT 2006
Melih Onvural wrote:
> This is the error message that I'm having a tough time interpreting:
> Traceback (most recent call last):
> File "pagerank.py", line 101, in ?
> main()
> File "pagerank.py", line 96, in main
> ch = strord(url)
> File "pagerank.py", line 81, in strord
> result[counter] = int(i);
> ValueError: invalid literal for int(): i
>
> and here is the full code:
>
> def strord(url):
> counter=0;
> for i in url:
> result[counter] = int(i);
> counter += 1;
>
> return result;
>
> Thanks
>
Says that you are trying to change the character 'i' into
an integer, which won't work. Put a print statement just
before your for loop and print out url. It doesn't just
contain numbers (as apparently you think it does).
You should also lose the semicolons, you are writing Python
now, not PHP ;-).
You might also want to write:
def strord(url):
return [int(i) for i in url]
Or just lose the function completely since it degrades to a
single list comprehension.
-Larry Bates
More information about the Python-list
mailing list