sitecustomize._vendor.importlib_metadata._text

Module Contents

Classes

FoldedCase

A case insensitive string class; behaves just like str

class sitecustomize._vendor.importlib_metadata._text.FoldedCase

Bases: str

A case insensitive string class; behaves just like str except compares equal when the only variation is case.

>>> s = FoldedCase('hello world')
>>> s == 'Hello World'
True
>>> 'Hello World' == s
True
>>> s != 'Hello World'
False
>>> s.index('O')
4
>>> s.split('O')
['hell', ' w', 'rld']
>>> sorted(map(FoldedCase, ['GAMMA', 'alpha', 'Beta']))
['alpha', 'Beta', 'GAMMA']

Sequence membership is straightforward.

>>> "Hello World" in [s]
True
>>> s in ["Hello World"]
True

You may test for set inclusion, but candidate and elements must both be folded.

>>> FoldedCase("Hello World") in {s}
True
>>> s in {FoldedCase("Hello World")}
True

String inclusion works as long as the FoldedCase object is on the right.

>>> "hello" in FoldedCase("Hello World")
True

But not if the FoldedCase object is on the left:

>>> FoldedCase('hello') in 'Hello World'
False

In that case, use in_:

>>> FoldedCase('hello').in_('Hello World')
True
>>> FoldedCase('hello') > FoldedCase('Hello')
False
__lt__(other)

Return self<value.

__gt__(other)

Return self>value.

__eq__(other)

Return self==value.

__ne__(other)

Return self!=value.

__hash__()

Return hash(self).

__contains__(other)

Return key in self.

in_(other)

Does self appear in other?

lower()

Return a copy of the string converted to lowercase.

index(sub)

S.index(sub[, start[, end]]) -> int

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation.

Raises ValueError when the substring is not found.

split(splitter=' ', maxsplit=0)

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including \n \r \t \f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits (starting from the left). -1 (the default value) means no limit.

Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.