string
index
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/string.py
Module Docs

A collection of string operations (most are no longer used).
 
Warning: most of the code you see here isn't normally used nowadays.
Beginning with Python 1.6, many of these functions are implemented as
methods on the standard string object. They used to be implemented by
a built-in module called strop, but strop is now obsolete itself.
 
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
punctuation -- a string containing all characters considered punctuation
printable -- a string containing all characters considered printable

 
Modules
       
re

 
Classes
       
__builtin__.object
Formatter
Template

 
class Formatter(__builtin__.object)
     Methods defined here:
check_unused_args(self, used_args, args, kwargs)
convert_field(self, value, conversion)
format(*args, **kwargs)
format_field(self, value, format_spec)
get_field(self, field_name, args, kwargs)
# given a field_name, find the object it references.
#  field_name:   the field being looked up, e.g. "0.name"
#                 or "lookup[3]"
#  used_args:    a set of which args have been used
#  args, kwargs: as passed in to vformat
get_value(self, key, args, kwargs)
parse(self, format_string)
# returns an iterable that contains tuples of the form:
# (literal_text, field_name, format_spec, conversion)
# literal_text can be zero length
# field_name can be None, in which case there's no
#  object to format and output
# if field_name is not None, it is looked up, formatted
#  with format_spec and conversion and then used
vformat(self, format_string, args, kwargs)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class Template(__builtin__.object)
    A string class for supporting $-substitutions.
 
  Methods defined here:
__init__(self, template)
safe_substitute(*args, **kws)
substitute(*args, **kws)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__metaclass__ = <class 'string._TemplateMetaclass'>
delimiter = '$'
idpattern = '[_a-z][_a-z0-9]*'
pattern = <_sre.SRE_Pattern object>

 
Functions
       
atof(s)
atof(s) -> float
 
Return the floating point number represented by the string s.
atoi(s, base=10)
atoi(s [,base]) -> int
 
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.
atol(s, base=10)
atol(s [,base]) -> long
 
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.
capitalize(s)
capitalize(s) -> string
 
Return a copy of the string s with only its first character
capitalized.
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.  If the optional second argument sep is absent or None,
runs of whitespace characters are replaced by a single space
and leading and trailing whitespace are removed, otherwise
sep is used to split and join the words.
center(s, width, *args)
center(s, width[, fillchar]) -> string
 
Return a center version of s, in a field of the specified
width. padded with spaces as needed.  The string is never
truncated.  If specified the fillchar is used instead of spaces.
count(s, *args)
count(s, sub[, start[,end]]) -> int
 
Return the number of occurrences of substring sub in string
s[start:end].  Optional arguments start and end are
interpreted as in slice notation.
expandtabs(s, tabsize=8)
expandtabs(s [,tabsize]) -> string
 
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).
find(s, *args)
find(s, sub [,start [,end]]) -> in
 
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.
index(s, *args)
index(s, sub [,start [,end]]) -> int
 
Like find but raises ValueError when the substring is not found.
join(words, sep=' ')
join(list [,sep]) -> string
 
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)
joinfields = join(words, sep=' ')
join(list [,sep]) -> string
 
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)
ljust(s, width, *args)
ljust(s, width[, fillchar]) -> string
 
Return a left-justified version of s, in a field of the
specified width, padded with spaces as needed.  The string is
never truncated.  If specified the fillchar is used instead of spaces.
lower(s)
lower(s) -> string
 
Return a copy of the string s converted to lowercase.
lstrip(s, chars=None)
lstrip(s [,chars]) -> string
 
Return a copy of the string s with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
maketrans(...)
maketrans(frm, to) -> string
 
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.
replace(s, old, new, maxreplace=-1)
replace (str, old, new[, maxreplace]) -> string
 
Return a copy of string str with all occurrences of substring
old replaced by new. If the optional argument maxreplace is
given, only the first maxreplace occurrences are replaced.
rfind(s, *args)
rfind(s, sub [,start [,end]]) -> int
 
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.
rindex(s, *args)
rindex(s, sub [,start [,end]]) -> int
 
Like rfind but raises ValueError when the substring is not found.
rjust(s, width, *args)
rjust(s, width[, fillchar]) -> string
 
Return a right-justified version of s, in a field of the
specified width, padded with spaces as needed.  The string is
never truncated.  If specified the fillchar is used instead of spaces.
rsplit(s, sep=None, maxsplit=-1)
rsplit(s [,sep [,maxsplit]]) -> list of strings
 
Return a list of the words in the string s, using sep as the
delimiter string, starting at the end of the string and working
to the front.  If maxsplit is given, at most maxsplit splits are
done. If sep is not specified or is None, any whitespace string
is a separator.
rstrip(s, chars=None)
rstrip(s [,chars]) -> string
 
Return a copy of the string s with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
split(s, sep=None, maxsplit=-1)
split(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 given, splits at no more than
maxsplit places (resulting in at most maxsplit+1 words).  If sep
is not specified or is None, any whitespace string is a separator.
 
(split and splitfields are synonymous)
splitfields = split(s, sep=None, maxsplit=-1)
split(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 given, splits at no more than
maxsplit places (resulting in at most maxsplit+1 words).  If sep
is not specified or is None, any whitespace string is a separator.
 
(split and splitfields are synonymous)
strip(s, chars=None)
strip(s [,chars]) -> string
 
Return a copy of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.
swapcase(s)
swapcase(s) -> string
 
Return a copy of the string s with upper case characters
converted to lowercase and vice versa.
translate(s, table, deletions='')
translate(s,table [,deletions]) -> string
 
Return a copy of the string s, where all characters occurring
in the optional argument deletions are removed, and the
remaining characters have been mapped through the given
translation table, which must be a string of length 256.  The
deletions argument is not allowed for Unicode strings.
upper(s)
upper(s) -> string
 
Return a copy of the string s converted to uppercase.
zfill(x, width)
zfill(x, width) -> string
 
Pad a numeric string x with zeros on the left, to fill a field
of the specified width.  The string x is never truncated.

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