Python标准库中一些模块
2016-09-13 18:11
417 查看
import re:调用正则表达式
提供高级字符串模式匹配方案。该模块中包含的关键函数有:
compile()--将一个RE表达式编译成一个可重用的RE对象
match()--试图从字符串的开始匹配一个模式
search()--找出字符串中所有匹配的项
sub()--进行查找替换操作
import string:引用字符串
from string import Template:调用Template,将字符串格式固定
Template对象有两个方法:substitute()和safe_substitute()
前者更为严谨,key缺少时会报一个KeyError异常,后者缺少key时,直接原封
不动显示字符串。
**************************************************
其主要实现方式为$xxx,其中字符串xxx不能以数字开头
如果$xxx需要和其他字符串接触,可用{}将xxx包裹起来
**************************************************
struct:字符串和二进制之间的转换
codecs:解码器注册和基类
crypt:进行单方面加密
difflib:找出序列间的不同
hashlib:多种不同安全哈希算法和信息摘要算法的API
hma:HMAC信息及安全算法的Python实现
md5:RSA的MD5信息摘要鉴权
rotor:提供多平台的加解密服务
sha:NIAT的安全哈希算法SHA
stringprep:提供用于IP协议的Unicode字符串
textwrap:文本包装和填充
unicodedata:Unicode数据库
提供高级字符串模式匹配方案。该模块中包含的关键函数有:
compile()--将一个RE表达式编译成一个可重用的RE对象
match()--试图从字符串的开始匹配一个模式
search()--找出字符串中所有匹配的项
sub()--进行查找替换操作
import string:引用字符串
from string import Template:调用Template,将字符串格式固定
Template对象有两个方法:substitute()和safe_substitute()
前者更为严谨,key缺少时会报一个KeyError异常,后者缺少key时,直接原封
不动显示字符串。
**************************************************
其主要实现方式为$xxx,其中字符串xxx不能以数字开头
如果$xxx需要和其他字符串接触,可用{}将xxx包裹起来
**************************************************
>>> from string import Template #调用Template >>> s = Template('There are ${howmany} ${lang} Quotation Symbols') >>> print s.substitute(lang = 'Python',howmany = 3) There are 3 Python Quotation Symbols >>> print s.substitute(lang = 'Python') <pre name="code" class="python">Traceback (most recent call last): #报错 File "<pyshell#146>", line 1, in <module> print s.substitute(lang = 'Python') File "D:\Python27\lib\string.py", line 172, in substitute return self.pattern.sub(convert, self.template) File "D:\Python27\lib\string.py", line 162, in convert val = mapping[named] KeyError: 'howmany' >>> print s.safe_substitute(lang = 'Python') There are ${howmany} Python Quotation Symbols >>>
struct:字符串和二进制之间的转换
codecs:解码器注册和基类
crypt:进行单方面加密
difflib:找出序列间的不同
hashlib:多种不同安全哈希算法和信息摘要算法的API
hma:HMAC信息及安全算法的Python实现
md5:RSA的MD5信息摘要鉴权
rotor:提供多平台的加解密服务
sha:NIAT的安全哈希算法SHA
stringprep:提供用于IP协议的Unicode字符串
textwrap:文本包装和填充
unicodedata:Unicode数据库
相关文章推荐
- Python标准库(非常经典的各种模块介绍)
- Python标准库-traceback模块
- python标准库random模块
- python基础教程_学习笔记14:标准库:一些最爱——re
- python基础教程_学习笔记13:标准库:一些最爱——sys
- Python标准库——os模块
- Python标准库(非常经典的各种模块介绍)
- python标准库fileinput模块学习
- Python标准库(非常经典的各种模块介绍)
- python基础教程_学习笔记16:标准库:一些最爱——random
- python urllib模块里面一些函数
- 9、Python-模块和标准库
- python标准库logging模块代码分析
- python标准库os模块学习
- Python标准库(非常经典的各种模块介绍)
- Python一些扩展模块
- Python标准库-string模块《未完待续》
- python:binascii模块 一些进制知识
- Python标准库(非常经典的各种模块介绍)
- python基础教程_学习笔记17:标准库:一些最爱——time