Python ValueError: invalid literal for int() with base 10 实用解决方法,valueerrorliteral
Python ValueError: invalid literal for int() with base 10 实用解决方法,valueerrorliteral
今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了
复制代码 代码如下:
totalCount = '100' totalPage = int(totalCount)/20
ValueError: invalid literal for int() with base 10的错误
网上同样的错误有人建议用round(float(“1.0″)),但是解决不了我这个问题,round(float(“1.0″))是用于解决浮点数转换为整形数的,
而我这个则是因为原字符串转换为整形后做除法,虽然一段时间内可能不报错,但时间久了就会提示(其实就是一个warning,但是会强制终止你的程序),正确解决方法如下:
复制代码 代码如下:
去除掉字符串中的非数字字符即可。亲测可用
相关内容
- Python实现删除文件但保留指定文件,
- Python os模块学习笔记,pythonos学习笔记
- Python实现线程池代码分享,python线程池代码
- Python安装第三方库的3种方法,python第三方库3种
- Python的装饰器模式与面向切面编程详解,python切面
- Python中有趣在__call__函数,python__call_函数
- Python中实现三目运算的方法,python运算
- Python Property属性的2种用法,pythonproperty
- 使用httplib模块来制作Python下HTTP客户端的方法,httplib
- 详解Python中的日志模块logging,pythonlogging
评论关闭