python标准库介绍——23 UserString 模块详解
==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// .
前者是对标准字符串类型的封装, 后者是一个变种, 允许你修改特定位置的字符(联想下列表就知道了). 注意 //MutableString// 并不是效率很好, 许多操作是通过切片和字符串连接实现的. 如果性能很对你的脚本来说重要的话, 你最好使用字符串片断的列表或者 ``array`` 模块.
[Example 2-17 #eg-2-17] 展示了 ``UserString`` 模块. ====Example 2-17. 使用 UserString 模块====[eg-2-17] ```
File: userstring-example-1.py import UserString class MyString(UserString.MutableString): def append(self, s):
self.data = self.data + s def insert(self, index, s):
self.data = self.data[index:] + s + self.data[index:] def remove(self, s):
self.data = self.data.replace(s, "") file = open("samples/book.txt")
text = file.read()
file.close() book = MyString(text) for bird in ["gannet", "robin", "nuthatch"]:
book.remove(bird) print book *B*...
C: The one without the !
P: The one without the -!!! They've ALL got the !! It's a
Standard British Bird, the , it's in all the books!!!
...*b*
```
python标准库介绍——23 UserString 模块详解的更多相关文章
- 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标准库介绍——36 popen2 模块详解
==popen2 模块== ``popen2`` 模块允许你执行外部命令, 并通过流来分别访问它的 ``stdin`` 和 ``stdout`` ( 可能还有 ``stderr`` ). 在 pyth ...
- python标准库介绍——22 UserList 模块详解
==UserList 模块== ``UserList`` 模块包含了一个可继承的列表类 (事实上是对内建列表类型的 Python 封装). 在 [Example 2-16 #eg-2-16] 中, / ...
- python标准库介绍——21 UserDict 模块详解
==UserDict 模块== ``UserDict`` 模块包含了一个可继承的字典类 (事实上是对内建字典类型的 Python 封装). [Example 2-15 #eg-2-15] 展示了一个增 ...
- python标准库介绍——20 cStringIO 模块详解
==cStringIO 模块== ``cStringIO`` 是一个可选的模块, 是 ``StringIO`` 的更快速实现. 它的工作方式和 ``StringIO`` 基本相同, 但是它不可以被继承 ...
随机推荐
- 【OpenCV】解析OpenCV中copyMakerBorder函数
Use the OpenCV function :copy_make_border:`copyMakeBorder <>` to set the borders (extra paddin ...
- DateNavigator
<Border BorderThickness="1,1,1,1" BorderBrush="Black" Grid.Column="1&quo ...
- VM虚拟机Failed to initialize remote display subsystem怎么办
1 如图所示,启动虚拟机的时候出现提示Failed to initialize remote display subsystem.怎么办 2 进入DOS窗口,输入net user __vmware_u ...
- strcpy sprintf memcpy 它们之间的区别
strcpy,sprintf,memcpy的区别 strcpy 函数操作的对象是 字符串,完成 从 源字符串 到 目的字符串 的 拷贝 功能. snprintf 函数操作的对象 不限于字符串:虽然目 ...
- Java从零开始学二(标识符和关键字)
标识符.关键字.注释 一.标识符 Java中的包.类.方法.参数和变量的名字由任意顺序的大小字母.数字.下划线(_).和美元符号($)组成, 标识符:不能以数字开头.也不能是JAVA中的保留关键字 如 ...
- 使用javacv录像,同时进行讯飞声纹认证
由于最近的demo中需要在活体检测的同时进行音视频录制 , 尝试使用MediaRecord和camera来录制视频 , 然而Camera.onPreviewFrame 不能与 MediaRecord ...
- linux常见题目
1. 把一个文件里面所有包含 abc 的行里面的 abc 替换成 def,然后输出第一列和第三列 cat abc.txt | grep abc | sed 's/abc/def/g' | awk '{ ...
- tomcat thread dump 分析
前言 Java Thread Dump 是一个非常有用的应用诊断工具, 通过thread dump出来的信息, 可以定位到你需要了解的线程, 以及这个线程的调用栈. 如果配合linux的top命令, ...
- MySQL优化小案例:连接数
错误代码:MySQL: ERROR 1040: Too many connections 经常会遇到这个错误,要么是业务增长,正常的访问量增多,要么是自己的max_connections设置的过小了 ...
- taro 引用相对路径图片
直接将相对路径放在src属性中,不起作用, 需要先import进来,最好把图片放到服务器上,然后直接写http路径 错误写法: <Image src="./images/front.p ...