下载、清理、提取和解析内容的简单工具
strutil的Python项目详细描述
结构
简单的帮助函数,用于交替使用字符串和正则表达式(主要是)。
要求
- Python3.4+
模块内容
strutil.is_string(obj)
Check if ^{tt2}$ is a string
strutil.is_regex(obj)
Check if ^{tt2}$ is a regular expression
- strutil.replace(text, old, new, count=None, strip=False)
用new替换text的old子集。
old类型可以是字符串或正则表达式。
如果strip,则删除所有前导/尾随空白。
如果count,则替换指定的出现次数,否则全部替换。
strutil.remove(text, what, count=None, strip=False)
Like ^{tt13}$, where ^{tt8}$ replacement is an empty string.
strutil.replace_each(text, items, count=None, strip=False)
Like ^{tt13}$, where each occurrence in ^{tt17}$ is a 2-tuple of ^{tt18}$ pair.
strutil.remove_each(text, items, count=None, strip=False)
Like ^{tt20}$, where each occurrence in ^{tt17}$ is ^{tt22}$ to remove.
strutil.contains(text, what)
Check if ^{tt22}$ occurs in ^{tt7}$
strutil.find_first(data, what)
Search for ^{tt22}$ in the iterable ^{tt28}$ and return the index of the first match. Return ^{tt29}$ if no match found.
strutil.splitter(text, token=None, expected=2, default='', strip=False)
Split ^{tt7}$ by ^{tt32}$ into at least ^{tt33}$ number of results.
When ^{tt32}$ is ^{tt29}$, the default for Python ^{tt36}$ is used, which will split on all whitespace.
^{tt32}$ may also be a regex.
If actual number of results is less than ^{tt33}$, pad with ^{tt39}$.
If ^{tt10}$, than do just that to each result.