python标准库介绍——20 cStringIO 模块详解
==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*
```
python标准库介绍——20 cStringIO 模块详解的更多相关文章
- python标准库介绍——27 random 模块详解
==random 模块== "Anyone who considers arithmetical methods of producing random digits is, of cour ...
- python标准库介绍——12 time 模块详解
==time 模块== ``time`` 模块提供了一些处理日期和一天内时间的函数. 它是建立在 C 运行时库的简单封装. 给定的日期和时间可以被表示为浮点型(从参考时间, 通常是 1970.1.1 ...
- python标准库介绍——10 sys 模块详解
==sys 模块== ``sys`` 模块提供了许多函数和变量来处理 Python 运行时环境的不同部分. === 处理命令行参数=== 在解释器启动后, ``argv`` 列表包含了传递给脚本的所有 ...
- python标准库介绍——30 code 模块详解
==code 模块== ``code`` 模块提供了一些用于模拟标准交互解释器行为的函数. ``compile_command`` 与内建 ``compile`` 函数行为相似, 但它会通过测试来保证 ...
- python标准库介绍——8 operator 模块详解
==operator 模块== ``operator`` 模块为 Python 提供了一个 "功能性" 的标准操作符接口. 当使用 ``map`` 以及 ``filter`` 一类 ...
- python标准库介绍——5 re模块详解
== re 模块== "Some people, when confronted with a problem, think 'I know, I'll use regular expres ...
- python标准库介绍——36 popen2 模块详解
==popen2 模块== ``popen2`` 模块允许你执行外部命令, 并通过流来分别访问它的 ``stdin`` 和 ``stdout`` ( 可能还有 ``stderr`` ). 在 pyth ...
- python标准库介绍——32 Queue 模块详解
Queue 模块 ``Queue`` 模块提供了一个线程安全的队列 (queue) 实现, 如 [Example 3-2 #eg-3-2] 所示. 你可以通过它在多个线程里安全访问同个对象. ==== ...
- python标准库介绍——23 UserString 模块详解
==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的 ...
随机推荐
- android 上传图片
public static String uploadPicture(String url, String uploadFile) { String resultcode = "1& ...
- linux pdb调试总结
1.首先gdb编译: gcc -g xxx.c -o xxx 2.然后 gdb xxx进入调试 break 行号 加入断点 (1)然后run就能够跑到下一个断点 (2)step(或s)单步跟踪 (3) ...
- ls命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/10/23/2734829.html ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下l ...
- Java从零开始学五(数据类型转换)
一.数据类型转换 分为“自动类型转换”和“强制类型转换” 二.自动类型转换 低级别------>高级别 byte b=7; int i=b; System.out.println("i ...
- 二叉查找树实现实例(C语言)
/* search_tree.h */ #ifndef _SEARCH_TREE_H #define _SEARCH_TREE_H struct tree_node; typedef struct t ...
- Mapreduce实例-分组排重(group by distinct)
public class GroupComparator implements RawComparator<MyBinaryKey> { @Override public int comp ...
- Guava学习之Preconditions
在编写程序的时候,很多时候都需要检查输入的参数是否符合我们的需要,比如人的年龄需要大于0,名字不能为空:如果不符合这两个要求,我们将认为这个对象是不合法的,这时候我们需要编写判断这些参数是否合法的函数 ...
- java 关于操作Collection的一点说明
java 中有一个工具类 Collections 其中的一个方法 static <T> boolean replaceAll(List<T> list, T oldVal, T ...
- Python pycharm(windows版本)部署spark环境
一 部署本地spark环境 1.1 安装好JDK 下载并安装好jdk1.7,配置完环境变量. 1.2 Spark环境变量配置 去http://spark.apache.o ...
- 微信小程序的零食商城
概述 这是一个微信小程序的商城应用,功能包括了首页.分类.购物车.个人中心.商品列表.商品详情.订单.地址管理等 详细 代码下载:http://www.demodashi.com/demo/10353 ...