python标准库介绍——20 cStringIO 模块详解
2024-08-25 13:36:11
==cStringIO 模块== ``cStringIO`` 是一个可选的模块, 是 ``StringIO`` 的更快速实现. 它的工作方式和 ``StringIO`` 基本相同,
但是它不可以被继承. [Example 2-11 #eg-2-11] 展示了 ``cStringIO`` 的用法, 另参考前一节. ====Example 2-11. 使用 cStringIO 模块====[eg-2-11] ```
File: cstringio-example-1.py import cStringIO MESSAGE = "That man is depriving a village somewhere of a computer scientist." file = cStringIO.StringIO(MESSAGE) print file.read() *B*That man is depriving a village somewhere of a computer scientist.*b*
``` 为了让你的代码尽可能快, 但同时保证兼容低版本的 Python ,你可以使用一个小技巧在 ``cStringIO``
不可用时启用 ``StringIO`` 模块, 如 [Example 2-12 #eg-2-12] 所示. ====Example 2-12. 后退至 StringIO====[eg-2-12] ```
File: cstringio-example-2.py try:
import cStringIO
StringIO = cStringIO
except ImportError:
import StringIO print StringIO *B*<module 'StringIO' (built-in)>*b*
```
最新文章
- iOS -- 处理推送消息
- Can’t Activate Reporting Services Service in SharePoint
- Log4net使用(一)
- python中2进制、10进制、16进制等之间的转换
- 【转】Linux网络相关查询脚本
- Flex基础相关
- java 、Android 提交参数转码问题
- windows下qtcreator添加ICE库文件
- HDOJ-1007 Quoit Design(最近点对问题)
- ECshop lib_base.php on line 1241 错误解决方法
- CSS设计指南之理解盒子模型
- php 基础篇 php 进阶篇
- Java项目中的一些注意事项
- Linux_破解密码-营救模式
- PS2键盘扫描码:通码与断码
- 背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本
- linux学习笔记-软件包的相关知识
- Unity接入Steamworks
- git 分支branch
- mysql 的 docker 镜像使用