python 中 字符串转换为数组,字典或表达式
来源:互联网 发布:stm32f103vb数据手册 编辑:程序博客网 时间:2024/05/29 11:43
在python中,一般都是使用eval,不过这个表达式不够安全。今天在stackoverflow上看到有人说ast这个模块
查了一下
ast.literal_eval(node_or_string)Safely evaluate an expression node or a Unicode or Latin-1 encoded string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, numbers, tuples, lists, dicts, booleans, and None.This can be used for safely evaluating strings containing Python expressions from untrusted sources without the need to parse the values oneself.
可以实现安全的代码转换,使用起来很简单
import astuserAnser = ast.literal_eval([1,2,3,4])
0 0
- python 中 字符串转换为数组,字典或表达式
- 转:python-将字符串转换为字典
- Python 中 字符串与字典间转换
- iOS对象(字典或数组)转化为JSon字符串
- iOS对象(字典或数组)转化为JSon字符串
- python中数组,元组,字典和字符串之间的转换
- python中数组,元组,字典和字符串之间的转换
- 用python正则表达式转换php数组到javascript字典
- java中字符串转换为字符串数组
- JS中json字符串转换为数组
- java中字节数组转换为字符串
- 字符串转换为表达式
- Python -- 字典转换为列表
- Python 列表转换为字典
- Python 之 将字符串数组转换为浮点型数组
- Python中,用eval强制将字符串转换为字典变量时候出错:NameError: name 'null' is not defined
- python中字符串和字典类型互相转换
- 字符串转换为数组
- static关键字
- linux parted 分区
- [Cocos2d-x]--CCTabelView显示指定行
- Join与子查询的对比
- AP聚类算法
- python 中 字符串转换为数组,字典或表达式
- 在CSDN开始写博客
- Android OpenGL 学习笔记 --开始篇
- 在VS 2012中把包应用程序的步骤
- 一个有序数组中找出两个数,使得两个数的和等于X的C++实现源代码
- eclipse中为了format的代码更加好看,少换行,可以设置java、xml、jsp的代码line width。
- 更新DataSet,遇到“对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成
- 100习惯,明天开始,第一目标,j2se完成。
- 你很幸运娶了我