python Unicode转为int
来源:互联网 发布:jquery传json数据 编辑:程序博客网 时间:2024/06/01 09:48
如果该unicode中是纯数字的话,直接将该unicode转为str(用string.encode("utf-8")),然后在用int函数进行转换,int(string)
但今天脚本中unicode有空格字符串,所以在进行int(string)的时候会报错:
ValueError: invalid literal for int() with base 10: '\xef\xbb\xbf\xef\xbb\xbf32'
里面的字符串转换为数据失败报错
用 filter(str.isdigit, string.encode("utf-8"))将unicode中的非数字的部分去掉,注:该函数不会改变原来的字符串对象,所以你要用一个变量接受返回来的值
如: strData =filter(str.isdigit, string.encode("utf-8")) , 然后再进行int转换 : int(strData)即可
阅读全文
0 0
- python Unicode转为int
- python将unicode转为str
- Python中字符、汉字、数字转为Unicode码
- Python将'\u'开头的字符串转为unicode编码
- python 将反斜杠u \u字符串转为unicode/utf8
- Python Unicode码无法转为中文字符问题
- python 读取csv文档hex字符串 转为int并存储
- python 将元组,列表中int 类型转为str
- java unicode 转为汉字
- 汉字转为unicode
- 字符转为unicode编码
- 中文转为unicode编码
- 中文转为unicode编码
- 字符串转为unicode
- INT转为CHAR
- int 转为16 进制数
- NSData转为Int
- 字符串转为int类型
- Spring IOC源码详解之容器初始化
- 用stm32cubemx点亮一个流水灯
- mac源码安装tensorflow
- 笨办法学 Python · 续 练习 8:`cut`
- 常用的git 指令
- python Unicode转为int
- JQ的serialize方法会进行编码
- Java内存模型JMM与可见性
- 逗号运算、关系运算、逻辑运算和条件运算
- react项目学习笔记四(redux和redux的中间件redux-thunk的认识)
- LeetCode
- An abandoned sentiment from past
- [HDU]6069 Counting Divisors
- STL中的所有算法(70个)