


Python ValueError: invalid literal for int() with base 10 实用
Jun 06, 2016 am 11:18 AM今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了
代码如下:
totalCount = '100' totalPage = int(totalCount)/20
ValueError: invalid literal for int() with base 10的错误
网上同样的错误有人建议用round(float(“1.0″)),但是解决不了我这个问题,round(float(“1.0″))是用于解决浮点数转换为整形数的,
而我这个则是因为原字符串转换为整形后做除法,虽然一段时间内可能不报错,但时间久了就会提示(其实就是一个warning,但是会强制终止你的程序),正确解决方法如下:
代码如下:
去除掉字符串中的非数字字符即可。亲测可用

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

For only $250, Hugging Face's technical director teaches you how to fine-tune Llama 3 step by step

Share several .NET open source AI and LLM related project frameworks

A complete guide to golang function debugging and analysis
