Python ValueError: invalid literal for int () with base 10 practical solution, valueerrorliteral
Today, when I was writing a crawler program, because I had to flip pages and split pages
Copy codeThe Code is as follows:
TotalCount = '000000' totalPage = int (totalCount)/20
ValueError: invalid literal for int () with base 10 Error
Someone suggested using round (float ("1.0") for the same error on the Internet, but it cannot solve this problem. round (float ("1.0 ″)) is used to convert a floating point to an integer,
This is because the original string is converted to an integer before division. Although no error may be reported within a period of time, it will prompt after a long time (in fact, it is a warning, but it will forcibly terminate your program). The correct solution is as follows:
Copy codeThe Code is as follows:
Remove non-numeric characters from the string. Test availability