Module strop
[hide private]
[frames] | no frames]

Module strop

Common string manipulations, optimized for speed.

Always use "import string" rather than referencing this module directly.

Functions [hide private]
float
atof(s)
Return the floating point number represented by the string s.
int
atoi(s, base=...)
Return the integer represented by the string s in the given base, which defaults to 10.
long
atol(s, base=...)
Return the long integer represented by the string s in the given base, which defaults to 10.
string
capitalize(s)
Return a copy of the string s with only its first character capitalized.
int
count(s, sub, start=..., end=...)
Return the number of occurrences of substring sub in string s[start:end].
 
expandtabs(...)
expandtabs(string, [tabsize]) -> string
in
find(s, sub, start=... , end=...)
Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end].
string
join(list, sep=...)
joinfields(list [,sep]) -> string
string
joinfields(list, sep=...)
joinfields(list [,sep]) -> string
string
lower(s)
Return a copy of the string s converted to lowercase.
string
lstrip(s)
Return a copy of the string s with leading whitespace removed.
string
maketrans(frm, to)
Return a translation table (a string of 256 bytes long) suitable for use in string.translate.
 
replace(...)
replace (str, old, new[, maxsplit]) -> string
int
rfind(s, sub, start=... , end=...)
Return the highest index in s where substring sub is found, such that sub is contained within s[start,end].
string
rstrip(s)
Return a copy of the string s with trailing whitespace removed.
list of strings
split(s, sep=... , maxsplit=...)
splitfields(s [,sep [,maxsplit]]) -> list of strings
list of strings
splitfields(s, sep=... , maxsplit=...)
splitfields(s [,sep [,maxsplit]]) -> list of strings
string
strip(s)
Return a copy of the string s with leading and trailing whitespace removed.
string
swapcase(s)
Return a copy of the string s with upper case characters converted to lowercase and vice versa.
string
translate(s, table, deletechars=...)
Return a copy of the string s, where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256.
string
upper(s)
Return a copy of the string s converted to uppercase.
Variables [hide private]
  lowercase = 'abcdefghijklmnopqrstuvwxyz'
  uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  whitespace = '\t\n\x0b\x0c\r '
Function Details [hide private]

atoi(s, base=...)

 

Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted.

Returns: int

atol(s, base=...)

 

Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0.

Returns: long

count(s, sub, start=..., end=...)

 

Return the number of occurrences of substring sub in string s[start:end]. Optional arguments start and end are interpreted as in slice notation.

Returns: int

expandtabs(...)

 

expandtabs(string, [tabsize]) -> string

Expand tabs in a string, i.e. replace them by one or more spaces, depending on the current column and the given tab size (default 8). The column number is reset to zero after each newline occurring in the string. This doesn't understand other non-printing characters.

find(s, sub, start=... , end=...)

 

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.

Return -1 on failure.

Returns: in

join(list, sep=...)

 

joinfields(list [,sep]) -> string

Return a string composed of the words in list, with intervening occurrences of sep. Sep defaults to a single space.

(join and joinfields are synonymous)

Returns: string

joinfields(list, sep=...)

 

joinfields(list [,sep]) -> string

Return a string composed of the words in list, with intervening occurrences of sep. Sep defaults to a single space.

(join and joinfields are synonymous)

Returns: string

maketrans(frm, to)

 

Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length.

Returns: string

replace(...)

 

replace (str, old, new[, maxsplit]) -> string

Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxsplit is given, only the first maxsplit occurrences are replaced.

rfind(s, sub, start=... , end=...)

 

Return the highest 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.

Return -1 on failure.

Returns: int

split(s, sep=... , maxsplit=...)

 

splitfields(s [,sep [,maxsplit]]) -> list of strings

Return a list of the words in the string s, using sep as the delimiter string. If maxsplit is nonzero, splits into at most maxsplit words. If sep is not specified, any whitespace string is a separator. Maxsplit defaults to 0.

(split and splitfields are synonymous)

Returns: list of strings

splitfields(s, sep=... , maxsplit=...)

 

splitfields(s [,sep [,maxsplit]]) -> list of strings

Return a list of the words in the string s, using sep as the delimiter string. If maxsplit is nonzero, splits into at most maxsplit words. If sep is not specified, any whitespace string is a separator. Maxsplit defaults to 0.

(split and splitfields are synonymous)

Returns: list of strings