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

Module stringold

Common string manipulations.

Public module variables:

whitespace -- a string containing all characters considered whitespace lowercase -- a string containing all characters considered lowercase letters uppercase -- a string containing all characters considered uppercase letters letters -- a string containing all characters considered letters digits -- a string containing all characters considered decimal digits hexdigits -- a string containing all characters considered hexadecimal digits octdigits -- a string containing all characters considered octal digits

Functions [hide private]
string
upper(s)
Return a copy of the string s converted to uppercase.
string
capitalize(s)
Return a copy of the string s with only its first character capitalized.
string
lstrip(s)
Return a copy of the string s with leading whitespace removed.
 
replace(s, old, new, maxsplit=0)
replace (str, old, new[, maxsplit]) -> string
 
capwords(s, sep=None)
capwords(s, [sep]) -> string
string
expandtabs(s, tabsize=...)
Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8).
string
strip(s)
Return a copy of the string s with leading and trailing whitespace removed.
string
ljust(s, width)
Return a left-justified version of s, in a field of the specified width, padded with spaces as needed.
int
index(s, sub, start=... , end=...)
Like find but raises ValueError when the substring is not found.
int
rindex(s, sub, start=... , end=...)
Like rfind but raises ValueError when the substring is not found.
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].
list of strings
splitfields(str, sep=... , maxsplit=...)
Return a list of the words in the string s, using sep as the delimiter string.
list of strings
split(str, sep=... , maxsplit=...)
Return a list of the words in the string s, using sep as the delimiter string.
string
rstrip(s)
Return a copy of the string s with trailing whitespace removed.
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.
int
count(s, sub, start=..., end=...)
Return the number of occurrences of substring sub in string s[start:end].
string
joinfields(list, sep=...)
Return a string composed of the words in list, with intervening occurrences of sep.
string
rjust(s, width)
Return a right-justified version of s, in a field of the specified width, padded with spaces as needed.
string
lower(s)
Return a copy of the string s converted to lowercase.
string
swapcase(s)
Return a copy of the string s with upper case characters converted to lowercase and vice versa.
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.
float
atof(s)
Return the floating point number represented by the string s.
string
join(list, sep=...)
Return a string composed of the words in list, with intervening occurrences of sep.
string
center(s, width)
Return a center version of s, in a field of the specified width.
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
zfill(x, width)
Pad a numeric string x with zeros on the left, to fill a field of the specified width.
Variables [hide private]
  _idmap = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x...
  _idmapL = None
  letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

Imports: _apply, _float, _int, _long, _StringType, index_error, octdigits, atol_error, atof_error, hexdigits, digits, atoi_error, maketrans, lowercase, uppercase, whitespace


Function Details [hide private]

replace(s, old, new, maxsplit=0)

 

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.

capwords(s, sep=None)

 

capwords(s, [sep]) -> string

Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. Note that this replaces runs of whitespace characters by a single space.

ljust(s, width)

 

Return a left-justified version of s, in a field of the specified width, padded with spaces as needed. The string is never truncated.

Returns: string

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

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

 

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

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

 

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

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

joinfields(list, sep=...)

 

Return a string composed of the words in list, with intervening occurrences of sep. The default separator is a single space.

(joinfields and join are synonymous)

Returns: string

rjust(s, width)

 

Return a right-justified version of s, in a field of the specified width, padded with spaces as needed. The string is never truncated.

Returns: string

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

join(list, sep=...)

 

Return a string composed of the words in list, with intervening occurrences of sep. The default separator is a single space.

(joinfields and join are synonymous)

Returns: string

center(s, width)

 

Return a center version of s, in a field of the specified width. padded with spaces as needed. The string is never truncated.

Returns: string

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

zfill(x, width)

 

Pad a numeric string x with zeros on the left, to fill a field of the specified width. The string x is never truncated.

Returns: string

Variables Details [hide private]

_idmap

Value:
'''\x00\x01\x02\x03\x04\x05\x06\x07\x08\t
\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\
\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX\
YZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x8\
6\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\\
x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa\
9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\\
xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xc\
...