python 字典类型中中文不转为unicode格式_将unicode字典字典转换为python中的字典

I have unicode u"{'code1':1,'code2':1}" and I want it in dictionary format.

I want it in {'code1':1,'code2':1} format.

I tried unicodedata.normalize('NFKD', my_data).encode('ascii','ignore') but it returns string not dictionary.

Can anyone help me?

解决方案

You can use built-in ast package:

import ast

d = ast.literal_eval("{'code1':1,'code2':1}")

Help on function literal_eval in module ast:

literal_eval(node_or_string)

Safely evaluate an expression node or a 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.


http://www.niftyadmin.cn/n/1172246.html

相关文章

关于搭建MyBatis框架(二)

由于在【关于使用Mybatis的使用说明(一)http://www.cnblogs.com/zdb292034/p/8675766.html】中存在不太完善地方,通过此片文档进行修订; 阅读指南:(1)本Mybatis中使用最简洁的方式;&…

UmengAppDemo【友盟统计SDK集成以及多渠道打包配置,基于V7.5.3版本】

版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这里只是记录下集成友盟统计SDK以及简单配置多渠道打包的步骤。所以1、该Demo不能运行;2、配置多渠道打包只是一种简单的写法,具体复杂写法请阅读参考资料。 使…

20170223--go语言入门

2019独角兽企业重金招聘Python工程师标准>>> 运行二进制go文件 golang 的安装步骤 在linux下编译windows程序 package mainfunc main(){ //mian为特殊函数,所以不传参和返回println("hello,go!") }func abc(参数)(返…

django python3 ldap_Django使用ldap认证登录

一、安装依赖包yum install gcc libffi-devel python-devel openssl-devel openldap-devel -y二、安装Python库pip install python_ldappip install django-auth-ldap三、修改django项目中的setting配置文件AUTHENTICATION_BACKENDS (django_auth_ldap.backend.LDAPBackend, #…

[PyQt5]基本控件21 - 滚动条QScrollBar

文章目录PyQt5系列文章效果图完整代码PyQt5系列文章 基本控件---1.按钮QPushButton2.标签QLabel3.可编辑框QTextEdit4.文本提示QToolTip5.单行输入框QLineEdit6.消息框QMessageBox7.单选按钮QRadioButton8.下拉列表QComboBox9.图片显示QPixmap10.分组框QGroupBox11.进度条QPro…

CNCF权威调研揭示K8s用户所面临的最大挑战

人们在使用及部署Kubernetes时会遇到各种各样的问题。一些挑战是使用Kubernetes时独有的,其他一些挑战则是伴随着一些技术的使用出现的典型问题。The New Stack发布的《Kubernetes的生态系统状况》报告总结了用户在挑选容器编排解决方案时的不同标准,以及…

Storm--命令行解析

strom的命令行解析 Commands:activateclasspathdeactivatedev-zookeeperdrpchelpjarkilllistlocalconfvaluelogviewermonitornimbusrebalanceremoteconfvaluereplshellsupervisoruiupload-credentialsversionHelp: help help <command> 1.详细解析-常用 1.jar 提交topol…

Python——re模块

re模块 1. 匹配常用方法 (1) findall 返回值&#xff1a;列表&#xff1a;列表中是所有匹配到的项 import re ret re.findall(a,eva egon yuan) #[a, a] print(ret) ret re.findall([a-z],eva egon yuan) #[eva, egon, yuan] print(ret) View Code(2) search ret …