文本处理--string模块

模块描述

A collection of string constants.

简要接口文档

__all__ = ["ascii_letters", "ascii_lowercase", "ascii_uppercase", "capwords",
           "digits", "hexdigits", "octdigits", "printable", "punctuation",
           "whitespace", "Formatter", "Template"]

模块全局变量

whitespace  -- a string containing all ASCII whitespace
ascii_lowercase  -- a string containing all ASCII lowercase letters
ascii_uppercase -- a string containing all ASCII uppercase letters
ascii_letters -- a string containing all ASCII letters
digits -- a string containing all ASCII decimal digits
hexdigits -- a string containing all ASCII hexadecimal digits
octdigits -- a string containing all ASCII octal digits
punctuation -- a string containing all ASCII punctuation characters
printable -- a string containing all ASCII characters considered printable

whitespace = ' \t\n\r\v\f'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace

模块函数

def capwords(s, sep=None):  -->string
参数:
  s  --> 文本字符串
  sep  --> 分割依据,默认空格
返回值:
  string  --> 返回按分隔符分割后单词首字母大写后的字符串

模块类

class Template(metaclass=_TemplateMetaclass):
    delimiter = '$'  #  默认分隔符
    idpattern = r'(?a:[_a-z][_a-z0-9]*)' #  默认匹配字符串
    braceidpattern = None #  默认分割字符串
    flags = _re.IGNORECASE #  默认字符格式

    def __init__(self, template):
        self.template = template

    def substitute(*args, **kws):
        return self.pattern.sub(convert, self.template)

    def safe_substitute(*args, **kws):
        return self.pattern.sub(convert, self.template)
class Formatter:
    def format(*args, **kwargs):
        return self.vformat(format_string, args, kwargs)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 9,368评论 0 3
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,160评论 1 32
  • 最后见你的那次是什么时候。 我如果知道那是最后一面我一定放下顾虑和矜持狠狠的拥抱你。 2015年,四月十八日。 你...
    小仙女WHR阅读 437评论 0 0
  • 刚刚刷简书,无意间看见一篇没有收益的文章。阅读量并不低,点赞的也不少,没有一个钻的收益。有古怪! 忍不住,点开悄悄...
    知农峰阅读 2,909评论 37 103
  • 本不应该出现在火焰杯里的名字出现了--哈利的名字。罗恩最开始不相信不是哈利自己放的名字,生气哈利不告诉自己...
    优秀鱼干儿阅读 875评论 0 3