import cgi

s = '<>&'
s += u'哈哈'
print type(s)
print s
r = cgi.escape(s)
print type(r)
print r
r = r.encode('gbk')
print type(r)
print r # <type 'unicode'>
# <>&哈哈
# <type 'unicode'>
# &lt;&gt;&amp;哈哈
# <type 'str'>
# &lt;&gt;&amp;哈哈

【Python】python2 html safe string的更多相关文章

  1. 【Python】python2.7 安装配置OpenCV2

    环境:Ubuntu16.04 anaconda Python2.7 opencv2.4.13 安装opencv后 import cv2 遇到错误信息: No module named cv2 安装op ...

  2. 【linux】【Python】python2.7安装pip9.0.1

    Centos7系统默认自带python2.7,但是没有安装pip. [root@localhost docker-elk]# python -V Python 2.7.5 [root@localhos ...

  3. 【python】3.x,string与bytes的区别(文本,二进制数据)

    Python 3对文本和二进制数据作了更为清晰的区分.文本总是Unicode,由str类型表示, 二进制数据则由bytes类型表示. 不能拼接字符串和字节包,也无法在字节包里搜索字符串(反之亦然),也 ...

  4. 【Python】python2.7安装pysvn

    wget最新的版本地址自己修改 1.编译安装apr.apr-utilwget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.5.2.tar ...

  5. 【python】python2.x中的除法

    在生信分析中有许多时候我们需要用到除法,在经历无数次break out 之后我终于发现原来python 2.x中只有整除,而没有浮点除法,这就是没有基础的弊病. 那么如何在python 2.x中运用除 ...

  6. 【Python】区分List 和String

    区分String和list String can't mutate 每次变更实质上开辟新的资源 List 可变更 警惕指针

  7. 【python】python2.x 与 python3.x区别对照+缩进错误解决方法

    仅仅列出我用到的,不全. 划重点: 1. urllib2 用 urllib.request 代替 2. urllib.urlencode 用 urllib.parse.urlencode 代替 3. ...

  8. 【Python】python2 str 编码检测

    python2 str 编码检测 import chardet s = 'sdffdfd' print type(s) print chardet.detect(s) s2 = '反反复复' prin ...

  9. 【LeetCode】678. Valid Parenthesis String 解题报告(Python)

    [LeetCode]678. Valid Parenthesis String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人 ...

随机推荐

  1. 【问题】Expandable数据集的定义的正确方法,TabActivity弃用替代,Gallery替代,imageswitcher

    Expandable 问题: http://www.cnblogs.com/xingyyy/p/3389611.html 扩展阅读:http://blog.csdn.net/lmj623565791/ ...

  2. C++类和对象的一个简单的实例

    题目:找出一个整形数组中的元素的最大值 下面,我们用类和对象的方法来做. #include<iostream> using namespace std; class Array_max{ ...

  3. Cannot uninstall 'enum34'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

    更新tensorflow时遇到报错 Found existing installation: enum34 1.0.4Cannot uninstall 'enum34'. It is a distut ...

  4. 阶段3-团队合作\项目-网络安全传输系统\sprint3-账号管理子系统设计\第2课-账号管理子系统设计

    账号管理子系统的设计 客户端需要登录到服务器,在服务器去查询数据库,进行验证该用户. 打开client.c文件 编译之 把它复制到开发板里面去 这个程序是在本地数据库测试的!!!!!!!!!!!!!! ...

  5. chrome - Vimium 插件超级方便快捷键

    Vimium插件作用 安装后,可以用定义好的快捷键操作浏览器,好用到爆粗口 下载地址 https://chrome.google.com/webstore/detail/vimium/dbepggeo ...

  6. 自签名配置HTTPS

    基于AFN3.0 1.将后台提供的.cer文件文件保存至本地 2.在封装的网络请求工具类中为AFN的AFSecurityPolicy属性赋值 -(AFSecurityPolicy *)customSe ...

  7. Linux命令使用

    命令行创建设置用户密码 $ sudo useradd -m -r username $ cat "username:password" | sudo chpasswd -m 查询u ...

  8. BK Componet Monitor

    Apache a) 启动服务前将监听地址改成0.0.0.0 b) 确认在文件“/etc/httpd/conf.modules.d/00-base.conf“中有加载mod_status模块 c) 新建 ...

  9. [CentOS7] systemd

    声明:本文主要总结自:鸟哥的Linux私房菜-第十七章.認識系統服務 (daemons),如有侵权,请通知博主 查看当前系统设定的服务启动脚本的类型:ls /usr/lib/systemd/syste ...

  10. SAS笔记(8) 利用数组重构SAS数据集

    在实际应用中,我们经常会把宽数据(一个患者一条观测)转化为长数据(一个患者多条观测)或者将长数据(一个患者多条观测)转换为宽数据(一个患者一条观测),在R中我们可以利用Reshape2包来实现.在SA ...