Python技巧(二)
2016-04-29 13:17
726 查看
1. 替换空格
2. 替换空格
>>> toSend = "FF F9 FF 00 00 FA FF F7 FF F4 FF F6 FF F7 FF F6 FF FD FF 05 00 03 00 06 00 05 00 04 00 06 00 06 00" >>> toSend.replace(' ', '').decode('hex') '\xff\xf9\xff\x00\x00\xfa\xff\xf7\xff\xf4\xff\xf6\xff\xf7\xff\xf6\xff\xfd\xff\x05\x00\x03\x00\x06\x00\x05\x00\x04\x00\x06\x00\x06\x00'
>>>
2. 替换空格
>>> toSend = "FF F9 FF 00 00 FA FF F7 FF F4 FF F6 FF F7 FF F6 FF FD FF 05 00 03 00 06 00 05 00" >>> ' '.join([x.decode('hex') for x in toSend.split()]) '\xff \xf9 \xff \x00 \x00 \xfa \xff \xf7 \xff \xf4 \xff \xf6 \xff \xf7 \xff \xf6 \xff \xfd \xff \x05 \x00 \x03 \x00 \x06 \x00 \x05 \x00'
相关文章推荐
- [python]fabric实现远程操作和部署
- Python itertools 模块 列表元素 字符串 反向遍历合并
- python中使用字符串前面加r
- ubuntu下python环境变量配置以及将模块放入正确位置
- [python]join函数操作字符串
- 史上最快python 异步消息队列zeromq 简介
- 使用Python进行多进程编程
- Python实现包含min函数的栈
- Python爬虫实战:百度贴吧—妈妈吧
- Python二叉搜索树与双向链表转换实现方法
- python中使用fork创建新的进程
- 游戏运维通用python简易脚本
- Python实现简单字典树的方法
- Python编码介绍——encode和decode
- Python自动化运维工具fabric的安装
- python3 + Django 学习之路(一)
- 解决fatal error: Python.h: No such file or directory
- python正则表达式
- python中使用epoll开发服务端程序
- Python的Urllib库的使用(爬虫基础)