Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libstring.tex @ 33258:993fd8acc90f legacy-trunk
Ah whoops, we didn't turn string into a package (thanks Neal!)
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Wed, 25 Aug 2004 03:09:58 +0000 |
| parents | 11a4fbc88a80 |
| children | e1ab2c12cd5e |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{string} --- |
|
10703
e4e800a78d8d
Make internal module references hyperlinks wherever it makes sense.
Fred Drake <fdrake@acm.org>
parents:
10229
diff
changeset
|
2 Common string operations} |
|
e4e800a78d8d
Make internal module references hyperlinks wherever it makes sense.
Fred Drake <fdrake@acm.org>
parents:
10229
diff
changeset
|
3 |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
8488
diff
changeset
|
4 \declaremodule{standard}{string} |
|
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
8488
diff
changeset
|
5 \modulesynopsis{Common string operations.} |
|
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
8488
diff
changeset
|
6 |
|
33258
993fd8acc90f
Ah whoops, we didn't turn string into a package (thanks Neal!)
Barry Warsaw <barry@python.org>
parents:
33257
diff
changeset
|
7 The \module{string} module contains a number of useful constants and classes, |
|
33257
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
8 as well as some deprecated legacy functions that are also available as methods |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
9 on strings. See the module \refmodule{re}\refstmodindex{re} for string |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
10 functions based on regular expressions. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
33257
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
12 \subsection{String constants} |
|
2463
e764b78a704f
add warning about strop
Guido van Rossum <guido@python.org>
parents:
2453
diff
changeset
|
13 |
| 15665 | 14 The constants defined in this module are: |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 |
|
18776
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
16 \begin{datadesc}{ascii_letters} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
17 The concatenation of the \constant{ascii_lowercase} and |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
18 \constant{ascii_uppercase} constants described below. This value is |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
19 not locale-dependent. |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
20 \end{datadesc} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
21 |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
22 \begin{datadesc}{ascii_lowercase} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
23 The lowercase letters \code{'abcdefghijklmnopqrstuvwxyz'}. This |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
24 value is not locale-dependent and will not change. |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
25 \end{datadesc} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
26 |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
27 \begin{datadesc}{ascii_uppercase} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
28 The uppercase letters \code{'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}. This |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
29 value is not locale-dependent and will not change. |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
30 \end{datadesc} |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
31 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 \begin{datadesc}{digits} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 The string \code{'0123456789'}. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 \begin{datadesc}{hexdigits} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 The string \code{'0123456789abcdefABCDEF'}. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 \begin{datadesc}{letters} |
| 12352 | 41 The concatenation of the strings \constant{lowercase} and |
|
18776
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
42 \constant{uppercase} described below. The specific value is |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
43 locale-dependent, and will be updated when |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
44 \function{locale.setlocale()} is called. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 \begin{datadesc}{lowercase} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 A string containing all the characters that are considered lowercase |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 letters. On most systems this is the string |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
1789
diff
changeset
|
50 \code{'abcdefghijklmnopqrstuvwxyz'}. Do not change its definition --- |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
51 the effect on the routines \function{upper()} and |
|
18776
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
52 \function{swapcase()} is undefined. The specific value is |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
53 locale-dependent, and will be updated when |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
54 \function{locale.setlocale()} is called. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 \begin{datadesc}{octdigits} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 The string \code{'01234567'}. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
14666
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
61 \begin{datadesc}{punctuation} |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
62 String of \ASCII{} characters which are considered punctuation |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
63 characters in the \samp{C} locale. |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
64 \end{datadesc} |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
65 |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
66 \begin{datadesc}{printable} |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
67 String of characters which are considered printable. This is a |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
68 combination of \constant{digits}, \constant{letters}, |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
69 \constant{punctuation}, and \constant{whitespace}. |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
70 \end{datadesc} |
|
1570854911ce
Document the "printable" and "punctuation" constants added to the string
Fred Drake <fdrake@acm.org>
parents:
14488
diff
changeset
|
71 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 \begin{datadesc}{uppercase} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 A string containing all the characters that are considered uppercase |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 letters. On most systems this is the string |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
1789
diff
changeset
|
75 \code{'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}. Do not change its definition --- |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
76 the effect on the routines \function{lower()} and |
|
18776
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
77 \function{swapcase()} is undefined. The specific value is |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
78 locale-dependent, and will be updated when |
|
22b2f4b436af
Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
Fred Drake <fdrake@acm.org>
parents:
17759
diff
changeset
|
79 \function{locale.setlocale()} is called. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 \begin{datadesc}{whitespace} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 A string containing all characters that are considered whitespace. |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 On most systems this includes the characters space, tab, linefeed, |
|
2453
cdd3a721b40e
a few typographical changes (e.g. -- => ---) and lots of new stuff in the WWW chapter
Guido van Rossum <guido@python.org>
parents:
1789
diff
changeset
|
85 return, formfeed, and vertical tab. Do not change its definition --- |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
86 the effect on the routines \function{strip()} and \function{split()} |
|
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
87 is undefined. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 \end{datadesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
33257
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
90 \subsection{Template strings} |
|
14488
aba7eb9d8d61
Add a reference to the material on string methods.
Fred Drake <fdrake@acm.org>
parents:
12976
diff
changeset
|
91 |
|
33257
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
92 Templates are Unicode strings that can be used to provide string substitutions |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
93 as described in \pep{292}. There is a \class{Template} class that is a |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
94 subclass of \class{unicode}, overriding the default \method{__mod__()} method. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
95 Instead of the normal \samp{\%}-based substitutions, Template strings support |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
96 \samp{\$}-based substitutions, using the following rules: |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
97 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
98 \begin{itemize} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
99 \item \samp{\$\$} is an escape; it is replaced with a single \samp{\$}. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
100 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
101 \item \samp{\$identifier} names a substitution placeholder matching a mapping |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
102 key of "identifier". By default, "identifier" must spell a Python |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
103 identifier. The first non-identifier character after the \samp{\$} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
104 character terminates this placeholder specification. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
105 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
106 \item \samp{\$\{identifier\}} is equivalent to \samp{\$identifier}. It is |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
107 required when valid identifier characters follow the placeholder but are |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
108 not part of the placeholder, e.g. "\$\{noun\}ification". |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
109 \end{itemize} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
110 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
111 Any other appearance of \samp{\$} in the string will result in a |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
112 \exception{ValueError} being raised. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
113 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
114 Template strings are used just like normal strings, in that the modulus |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
115 operator is used to interpolate a dictionary of values into a Template string, |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
116 e.g.: |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
117 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
118 \begin{verbatim} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
119 >>> from string import Template |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
120 >>> s = Template('$who likes $what') |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
121 >>> print s % dict(who='tim', what='kung pao') |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
122 tim likes kung pao |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
123 >>> Template('Give $who $100') % dict(who='tim') |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
124 Traceback (most recent call last): |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
125 [...] |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
126 ValueError: Invalid placeholder at index 10 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
127 \end{verbatim} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
128 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
129 There is also a \class{SafeTemplate} class, derived from \class{Template} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
130 which acts the same as \class{Template}, except that if placeholders are |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
131 missing in the interpolation dictionary, no \exception{KeyError} will be |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
132 raised. Instead the original placeholder (with or without the braces, as |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
133 appropriate) will be used: |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
134 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
135 \begin{verbatim} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
136 >>> from string import SafeTemplate |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
137 >>> s = SafeTemplate('$who likes $what for ${meal}') |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
138 >>> print s % dict(who='tim') |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
139 tim likes $what for ${meal} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
140 \end{verbatim} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
141 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
142 The values in the mapping will automatically be converted to Unicode strings, |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
143 using the built-in \function{unicode()} function, which will be called without |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
144 optional arguments \var{encoding} or \var{errors}. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
145 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
146 Advanced usage: you can derive subclasses of \class{Template} or |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
147 \class{SafeTemplate} to use application-specific placeholder rules. To do |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
148 this, you override the class attribute \member{pattern}; the value must be a |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
149 compiled regular expression object with four named capturing groups. The |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
150 capturing groups correspond to the rules given above, along with the invalid |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
151 placeholder rule: |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
152 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
153 \begin{itemize} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
154 \item \var{escaped} -- This group matches the escape sequence, i.e. \samp{\$\$} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
155 in the default pattern. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
156 \item \var{named} -- This group matches the unbraced placeholder name; it |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
157 should not include the \samp{\$} in capturing group. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
158 \item \var{braced} -- This group matches the brace delimited placeholder name; |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
159 it should not include either the \samp{\$} or braces in the capturing |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
160 group. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
161 \item \var{bogus} -- This group matches any other \samp{\$}. It usually just |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
162 matches a single \samp{\$} and should appear last. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
163 \end{itemize} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
164 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
165 \subsection{String functions} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
166 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
167 The following functions are available to operate on string and Unicode |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
168 objects. They are not available as string methods. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
169 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
170 \begin{funcdesc}{capwords}{s} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
171 Split the argument into words using \function{split()}, capitalize |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
172 each word using \function{capitalize()}, and join the capitalized |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
173 words using \function{join()}. Note that this replaces runs of |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
174 whitespace characters by a single space, and removes leading and |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
175 trailing whitespace. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
176 \end{funcdesc} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
177 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
178 \begin{funcdesc}{maketrans}{from, to} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
179 Return a translation table suitable for passing to |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
180 \function{translate()} or \function{regex.compile()}, that will map |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
181 each character in \var{from} into the character at the same position |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
182 in \var{to}; \var{from} and \var{to} must have the same length. |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
183 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
184 \warning{Don't use strings derived from \constant{lowercase} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
185 and \constant{uppercase} as arguments; in some locales, these don't have |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
186 the same length. For case conversions, always use |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
187 \function{lower()} and \function{upper()}.} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
188 \end{funcdesc} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
189 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
190 \subsection{Deprecated string functions} |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
191 |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
192 The following list of functions are also defined as methods of string and |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
193 Unicode objects; see ``String Methods'' (section |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
194 \ref{string-methods}) for more information on those. You should consider |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
195 these functions as deprecated, although they will not be removed until Python |
|
11a4fbc88a80
PEP 292 classes Template and SafeTemplate are added to the string module.
Barry Warsaw <barry@python.org>
parents:
32761
diff
changeset
|
196 3.0. The functions defined in this module are: |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 \begin{funcdesc}{atof}{s} |
|
15009
9847b486d15f
Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
199 \deprecated{2.0}{Use the \function{float()} built-in function.} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
200 Convert a string to a floating point number. The string must have |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
201 the standard syntax for a floating point literal in Python, |
|
10229
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
202 optionally preceded by a sign (\samp{+} or \samp{-}). Note that |
|
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
203 this behaves identical to the built-in function |
|
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
204 \function{float()}\bifuncindex{float} when passed a string. |
|
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
205 |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
18776
diff
changeset
|
206 \note{When passing in a string, values for NaN\index{NaN} |
|
10229
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
207 and Infinity\index{Infinity} may be returned, depending on the |
|
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
208 underlying C library. The specific set of strings accepted which |
|
ce57eb30968a
Add notes to __builtin__.float() and string.atof() that the NaN and Inf
Fred Drake <fdrake@acm.org>
parents:
10222
diff
changeset
|
209 cause these values to be returned depends entirely on the C library |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
18776
diff
changeset
|
210 and is known to vary.} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
213 \begin{funcdesc}{atoi}{s\optional{, base}} |
|
15009
9847b486d15f
Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
214 \deprecated{2.0}{Use the \function{int()} built-in function.} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
215 Convert string \var{s} to an integer in the given \var{base}. The |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
216 string must consist of one or more digits, optionally preceded by a |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
217 sign (\samp{+} or \samp{-}). The \var{base} defaults to 10. If it |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
218 is 0, a default base is chosen depending on the leading characters |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
219 of the string (after stripping the sign): \samp{0x} or \samp{0X} |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
220 means 16, \samp{0} means 8, anything else means 10. If \var{base} |
|
14710
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14666
diff
changeset
|
221 is 16, a leading \samp{0x} or \samp{0X} is always accepted, though |
|
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14666
diff
changeset
|
222 not required. This behaves identically to the built-in function |
|
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14666
diff
changeset
|
223 \function{int()} when passed a string. (Also note: for a more |
|
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14666
diff
changeset
|
224 flexible interpretation of numeric literals, use the built-in |
|
ac6df0494c58
Fixed a number of small problems reported by Detlef Lannert
Fred Drake <fdrake@acm.org>
parents:
14666
diff
changeset
|
225 function \function{eval()}\bifuncindex{eval}.) |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
228 \begin{funcdesc}{atol}{s\optional{, base}} |
|
15009
9847b486d15f
Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
229 \deprecated{2.0}{Use the \function{long()} built-in function.} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
230 Convert string \var{s} to a long integer in the given \var{base}. |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
231 The string must consist of one or more digits, optionally preceded |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
232 by a sign (\samp{+} or \samp{-}). The \var{base} argument has the |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
233 same meaning as for \function{atoi()}. A trailing \samp{l} or |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
234 \samp{L} is not allowed, except if the base is 0. Note that when |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
235 invoked without \var{base} or with \var{base} set to 10, this |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
236 behaves identical to the built-in function |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
237 \function{long()}\bifuncindex{long} when passed a string. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
239 |
|
3996
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
240 \begin{funcdesc}{capitalize}{word} |
|
23942
6e2a3c5700ac
Make the docs for string.capitalize() match those of str.capitalize()
Fred Drake <fdrake@acm.org>
parents:
23225
diff
changeset
|
241 Return a copy of \var{word} with only its first character capitalized. |
|
3996
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
242 \end{funcdesc} |
|
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
243 |
|
15009
9847b486d15f
Added deprecation notices to atof(), atoi(), and atol(), recommending
Fred Drake <fdrake@acm.org>
parents:
14710
diff
changeset
|
244 \begin{funcdesc}{expandtabs}{s\optional{, tabsize}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
245 Expand tabs in a string, i.e.\ replace them by one or more spaces, |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
246 depending on the current column and the given tab size. The column |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
247 number is reset to zero after each newline occurring in the string. |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
248 This doesn't understand other non-printing characters or escape |
|
9952
e5d0df824bf3
Document the default for tabsize in expandtabs().
Guido van Rossum <guido@python.org>
parents:
9675
diff
changeset
|
249 sequences. The tab size defaults to 8. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
252 \begin{funcdesc}{find}{s, sub\optional{, start\optional{,end}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
253 Return the lowest index in \var{s} where the substring \var{sub} is |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
254 found such that \var{sub} is wholly contained in |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
255 \code{\var{s}[\var{start}:\var{end}]}. Return \code{-1} on failure. |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
256 Defaults for \var{start} and \var{end} and interpretation of |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
257 negative values is the same as for slices. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
260 \begin{funcdesc}{rfind}{s, sub\optional{, start\optional{, end}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
261 Like \function{find()} but find the highest index. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
264 \begin{funcdesc}{index}{s, sub\optional{, start\optional{, end}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
265 Like \function{find()} but raise \exception{ValueError} when the |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
266 substring is not found. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
269 \begin{funcdesc}{rindex}{s, sub\optional{, start\optional{, end}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
270 Like \function{rfind()} but raise \exception{ValueError} when the |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
271 substring is not found. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
273 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
274 \begin{funcdesc}{count}{s, sub\optional{, start\optional{, end}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
275 Return the number of (non-overlapping) occurrences of substring |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
276 \var{sub} in string \code{\var{s}[\var{start}:\var{end}]}. |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
277 Defaults for \var{start} and \var{end} and interpretation of |
| 12976 | 278 negative values are the same as for slices. |
|
1750
0b645726957e
libsocket.tex: send[to] returns nbytes.
Guido van Rossum <guido@python.org>
parents:
1471
diff
changeset
|
279 \end{funcdesc} |
|
0b645726957e
libsocket.tex: send[to] returns nbytes.
Guido van Rossum <guido@python.org>
parents:
1471
diff
changeset
|
280 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 \begin{funcdesc}{lower}{s} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
282 Return a copy of \var{s}, but with upper case letters converted to |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
283 lower case. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
285 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
286 \begin{funcdesc}{split}{s\optional{, sep\optional{, maxsplit}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
287 Return a list of the words of the string \var{s}. If the optional |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
288 second argument \var{sep} is absent or \code{None}, the words are |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
289 separated by arbitrary strings of whitespace characters (space, tab, |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
290 newline, return, formfeed). If the second argument \var{sep} is |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
291 present and not \code{None}, it specifies a string to be used as the |
|
10882
06def8042d8e
Typo reported by Gerry Wiener <wiener@rap.ucar.edu>:
Fred Drake <fdrake@acm.org>
parents:
10703
diff
changeset
|
292 word separator. The returned list will then have one more item |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
293 than the number of non-overlapping occurrences of the separator in |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
294 the string. The optional third argument \var{maxsplit} defaults to |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
295 0. If it is nonzero, at most \var{maxsplit} number of splits occur, |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
296 and the remainder of the string is returned as the final element of |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
297 the list (thus, the list will have at most \code{\var{maxsplit}+1} |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
298 elements). |
|
31735
ee0ba00b277c
Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31289
diff
changeset
|
299 |
|
ee0ba00b277c
Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31289
diff
changeset
|
300 The behavior of split on an empty string depends on the value of \var{sep}. |
|
ee0ba00b277c
Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31289
diff
changeset
|
301 If \var{sep} is not specified, or specified as \code{None}, the result will |
|
ee0ba00b277c
Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31289
diff
changeset
|
302 be an empty list. If \var{sep} is specified as any string, the result will |
|
ee0ba00b277c
Modified string.split documentation to reflect behaviour of splitting emtpy string. Closes SF bug #811604
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31289
diff
changeset
|
303 be a list containing one element which is an empty string. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
30937
diff
changeset
|
306 \begin{funcdesc}{rsplit}{s\optional{, sep\optional{, maxsplit}}} |
|
31206
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
307 Return a list of the words of the string \var{s}, scanning \var{s} |
|
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
308 from the end. To all intents and purposes, the resulting list of |
|
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
309 words is the same as returned by \function{split()}, except when the |
|
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
310 optional third argument \var{maxsplit} is explicitly specified and |
|
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
311 nonzero. When \var{maxsplit} is nonzero, at most \var{maxsplit} |
| 31289 | 312 number of splits -- the \emph{rightmost} ones -- occur, and the remainder |
|
31206
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
313 of the string is returned as the first element of the list (thus, the |
|
3771ff99d5f2
Update documentations for str.rsplit() with Alex Martelli's rewrite.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
31199
diff
changeset
|
314 list will have at most \code{\var{maxsplit}+1} elements). |
|
31199
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
30937
diff
changeset
|
315 \versionadded{2.4} |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
30937
diff
changeset
|
316 \end{funcdesc} |
|
504943c89193
Add rsplit method for str and unicode builtin types.
Hye-Shik Chang <hyeshik@gmail.com>
parents:
30937
diff
changeset
|
317 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
318 \begin{funcdesc}{splitfields}{s\optional{, sep\optional{, maxsplit}}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
319 This function behaves identically to \function{split()}. (In the |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
320 past, \function{split()} was only used with one argument, while |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
321 \function{splitfields()} was only used with two arguments.) |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
324 \begin{funcdesc}{join}{words\optional{, sep}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
325 Concatenate a list or tuple of words with intervening occurrences of |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
326 \var{sep}. The default value for \var{sep} is a single space |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
327 character. It is always true that |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
328 \samp{string.join(string.split(\var{s}, \var{sep}), \var{sep})} |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
329 equals \var{s}. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
332 \begin{funcdesc}{joinfields}{words\optional{, sep}} |
|
25229
8775dee60d89
Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents:
23942
diff
changeset
|
333 This function behaves identically to \function{join()}. (In the past, |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
334 \function{join()} was only used with one argument, while |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
335 \function{joinfields()} was only used with two arguments.) |
|
25229
8775dee60d89
Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents:
23942
diff
changeset
|
336 Note that there is no \method{joinfields()} method on string |
|
8775dee60d89
Fix typo reported by Paul Clifford.
Fred Drake <fdrake@acm.org>
parents:
23942
diff
changeset
|
337 objects; use the \method{join()} method instead. |
|
3996
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
338 \end{funcdesc} |
|
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
339 |
|
23225
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
340 \begin{funcdesc}{lstrip}{s\optional{, chars}} |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
341 Return a copy of the string with leading characters removed. If |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
342 \var{chars} is omitted or \code{None}, whitespace characters are |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
343 removed. If given and not \code{None}, \var{chars} must be a string; |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
344 the characters in the string will be stripped from the beginning of |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
345 the string this method is called on. |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25229
diff
changeset
|
346 \versionchanged[The \var{chars} parameter was added. The \var{chars} |
|
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25229
diff
changeset
|
347 parameter cannot be passed in earlier 2.2 versions]{2.2.3} |
|
3996
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
348 \end{funcdesc} |
|
0ec2ce97b8e3
Added capitalize, capwords, lstrip, rstrip, and optional 3rd argument
Guido van Rossum <guido@python.org>
parents:
3858
diff
changeset
|
349 |
|
23225
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
350 \begin{funcdesc}{rstrip}{s\optional{, chars}} |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
351 Return a copy of the string with trailing characters removed. If |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
352 \var{chars} is omitted or \code{None}, whitespace characters are |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
353 removed. If given and not \code{None}, \var{chars} must be a string; |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
354 the characters in the string will be stripped from the end of the |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
355 string this method is called on. |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25229
diff
changeset
|
356 \versionchanged[The \var{chars} parameter was added. The \var{chars} |
|
32761
61be904a1d4e
Patch #993187: Make rstrip doc similar to lstrip.
Martin v. Löwis <martin@v.loewis.de>
parents:
31735
diff
changeset
|
357 parameter cannot be passed in earlier 2.2 versions]{2.2.3} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
23225
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
360 \begin{funcdesc}{strip}{s\optional{, chars}} |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
361 Return a copy of the string with leading and trailing characters |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
362 removed. If \var{chars} is omitted or \code{None}, whitespace |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
363 characters are removed. If given and not \code{None}, \var{chars} |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
364 must be a string; the characters in the string will be stripped from |
|
e639e34ef901
Apply patch diff.txt from SF feature request
Walter Dörwald <walter@livinglogic.de>
parents:
20580
diff
changeset
|
365 the both ends of the string this method is called on. |
|
28575
215f1f4851a4
Attempt to make all the various string *strip methods the same.
Neal Norwitz <nnorwitz@gmail.com>
parents:
25229
diff
changeset
|
366 \versionchanged[The \var{chars} parameter was added. The \var{chars} |
|
28665
239429dc029f
Oops, missed updating doc to correct version for split
Neal Norwitz <nnorwitz@gmail.com>
parents:
28575
diff
changeset
|
367 parameter cannot be passed in earlier 2.2 versions]{2.2.3} |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 \begin{funcdesc}{swapcase}{s} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
371 Return a copy of \var{s}, but with lower case letters |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
372 converted to upper case and vice versa. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 |
|
3858
8b71ea5dacc8
Added maketrans() and optional 3rd arg to translate() (chars to delete).
Guido van Rossum <guido@python.org>
parents:
3379
diff
changeset
|
375 \begin{funcdesc}{translate}{s, table\optional{, deletechars}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
376 Delete all characters from \var{s} that are in \var{deletechars} (if |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
377 present), and then translate the characters using \var{table}, which |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
378 must be a 256-character string giving the translation for each |
|
29833
d45d317fda35
SF bug #706546: u''.translate not documented
Raymond Hettinger <python@rcn.com>
parents:
28665
diff
changeset
|
379 character value, indexed by its ordinal. |
|
3084
91c1bb75e945
added string.translate(s, table)
Guido van Rossum <guido@python.org>
parents:
2647
diff
changeset
|
380 \end{funcdesc} |
|
91c1bb75e945
added string.translate(s, table)
Guido van Rossum <guido@python.org>
parents:
2647
diff
changeset
|
381 |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 \begin{funcdesc}{upper}{s} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
383 Return a copy of \var{s}, but with lower case letters converted to |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
384 upper case. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
387 \begin{funcdesc}{ljust}{s, width} |
|
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
388 \funcline{rjust}{s, width} |
|
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
389 \funcline{center}{s, width} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
390 These functions respectively left-justify, right-justify and center |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
391 a string in a field of given width. They return a string that is at |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
392 least \var{width} characters wide, created by padding the string |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
393 \var{s} with spaces until the given width on the right, left or both |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
394 sides. The string is never truncated. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 \end{funcdesc} |
|
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 |
|
7712
0cbc9df882b6
Change "\," to just "," in function signatures. This is easier to maintain,
Fred Drake <fdrake@acm.org>
parents:
7277
diff
changeset
|
397 \begin{funcdesc}{zfill}{s, width} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
398 Pad a numeric string on the left with zero digits until the given |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
399 width is reached. Strings starting with a sign are handled |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
400 correctly. |
|
1471
2ec96140a36b
Restructured library documentation
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 \end{funcdesc} |
|
2463
e764b78a704f
add warning about strop
Guido van Rossum <guido@python.org>
parents:
2453
diff
changeset
|
402 |
|
30937
51ebf5474f3d
Patch #843088: Fix typos. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29893
diff
changeset
|
403 \begin{funcdesc}{replace}{str, old, new\optional{, maxreplace}} |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
404 Return a copy of string \var{str} with all occurrences of substring |
|
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
405 \var{old} replaced by \var{new}. If the optional argument |
|
30937
51ebf5474f3d
Patch #843088: Fix typos. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
29893
diff
changeset
|
406 \var{maxreplace} is given, the first \var{maxreplace} occurrences are |
|
9675
b78049fefceb
Clarify descriptions of some operations; it's not always clear that
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
407 replaced. |
|
5212
1f38d5fb3d23
Added docs for replace() and replace1().
Guido van Rossum <guido@python.org>
parents:
5188
diff
changeset
|
408 \end{funcdesc} |
