ValueError: invalid literal for int() with base 10: ''

有时候需要用int()函数转换字符串为整型,但是切记int()只能转化由纯数字组成的字符串,如下例:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

str1='214567'
str2=''
str3='fsdf214356'
int(str1)
214567
int(str2)
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
int(str2)
ValueError: invalid literal for int() with base 10: ''#不可转换空字符串为整型
int(str3)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
int(str3)
ValueError: invalid literal for int() with base 10: 'fsdf214356'#不可转换非纯数字组成的字符串

非纯数字组成的字符串强转为整型会报错:ValueError: invalid literal for int() with base 10

转载于https://www.cnblogs.com/helloworldcc/p/9681546.html

ValueError: invalid literal for int() with base 10: ''

原文地址:https://www.cnblogs.com/hanfe1/p/12255192.html

时间: 2024-08-09 10:02:31

ValueError: invalid literal for int() with base 10: ''的相关文章

Python中ValueError: invalid literal for int() with base 10 的实用解决办法

今天在写爬虫程序的时候由于要翻页,做除法分页的时候出现了 1 2 totalCount = '100' totalPage = int(totalCount)/20 ValueError: invalid literal for int() with base 10的错误 网上同样的错误有人建议用round(float(“1.0″)),但是解决不了我这个问题,round(float(“1.0″))是用于解决浮点数转换为整形数的, 而我这个则是因为原字符串转换为整形后做除法,虽然一段时间内可能不报

celery中配置redis密码时的ValueError: invalid literal for int() with base 10: &#39;xxxx&#39;

原配置: celery_broker = 'redis://:xxxx#[email protected]:6379/0' # docker0 错误原因: 密码中不能有 # https://blog.csdn.net/liushaochan123/article/details/8885116 celery中配置redis密码时的ValueError: invalid literal for int() with base 10: 'xxxx' 原文地址:https://www.cnblogs.

python 小数相加报错 invalid literal for int() with base 10

for i in column1: x = int(i) s += xprint "sum:",s,"count:",len(column1)# round (s / len(column1), 3)print "avg",round (s / len(column1), 3) Traceback (most recent call last): File "C:/3/csv测试.py", line 26, in <mo

scrapy-redis 报 invalid literal for int() with base 10:

我在scrapy settings.py中填的REDIS_URL是这样的, 密码中含有特俗符合, 导致连接不上redis服务器 REDIS_URL = 'redis://:^*,dfdas.*,@192.168.10.34:6379/1' 网上有人说,先encode密码, 连接的时候再decode, 但是这样就要改动到scrapy-redis的源码,有一种不需改变源码的方式更方便一些,如下 REDIS_HOST = '192.168.10.34'REDIS_PORT = 6379REDIS_PA

Mac 下 Python os.listdir 出现 invalid literal for int() with base 10 错误

因为 Mac 下的 .DS_Store 也会包含进去 解决方法: def listdirInMac(path): os_list = os.listdir(path) for item in os_list: if item.startswith('.') and os.path.isfile(os.path.join(path, item)): os_list.remove(item) return os_list

Python标准库:内置函数int(x, base=10)

本函数实现从浮点数或数字字符串转换为整数.如果参数x不是一个数字,必须是字符串.数组bytes或bytearray类型.参数base是指字符串参数的进制,默认10就是表示使用十进制.当它是2时,表示二进制的字符串转换.当它是8时,表示是八进制的字符串转换.当它是16时,表示是十六进制的字符串转换.然而当它是0时,它表示不是0进制,而跟十进制是一样的. 例子: print(int('20', 8)) print(int('0x20', 16)) print(int('0o73', 8)) prin

int (*(*fp)(void *))[10]; 指向函数的指针类型

<pre lang="c" escaped="true">int (*(*fp)(void *))[10]; //这个类型用typedef分解出来 // 第一步:此指针是一个指向函数T1的指针typedef int (*T1(void *))[10];T1 *fp; // 第二步:T1 是一个函数,返回值是T2,参数为(void *)typedef int (*T2)[10];typedef T2 T1(void *);T1 *fp; // 第三步:T2

convert from base 10 to base 2

COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Hence, we convert from base 10 to base 2 by repeated divisions by 2. The remainders and the final quotient, 1, give us, in order of increas-ing significance, the binary di

ValueError: Invalid leaf XXX

Bug:ValueError: Invalid leaf XXX 无效的搜索条件--检查search函数中的domain表达式格式!是否少了括号! search(['user_id', '=', user_id,]) 上式错误,应该改为: search([('user_id', '=', user_id),]) 原文地址:https://www.cnblogs.com/cnodoo/p/9281381.html