]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Documented new built-in function vars().
authorGuido van Rossum <guido@python.org>
Thu, 21 Apr 1994 10:32:28 +0000 (10:32 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 21 Apr 1994 10:32:28 +0000 (10:32 +0000)
Documented new formatting features: %s takes any type, and
'%(key)format' % dictionary.
Documented posixpath.expandvars().

Doc/lib/libfuncs.tex
Doc/lib/libppath.tex
Doc/lib/libtypes.tex
Doc/libfuncs.tex
Doc/libppath.tex
Doc/libtypes.tex

index 73bc1454b70ff88ced49ed0d9ee164e7fd1f68e1..ab4b03c98b52da83f8ad15d7b2d519ae8864915d 100644 (file)
@@ -355,6 +355,18 @@ its goal is to return a printable string.
 \end{verbatim}\ecode
 \end{funcdesc}
 
+\begin{funcdesc}{vars}{}
+Without arguments, return a dictionary corresponding to the current
+local symbol table.  With a module, class or class instance object as
+argument (or anything else that has a \code{__dict__} attribute),
+returns a dictionary corresponding to the object's symbol table.
+The returned dictionary should not be modified: the effects on the
+corresponding symbol table are undefined.%
+\footnote{In the current implementation, local variable bindings
+cannot normally be affected this way, but variables retrieved from
+other scopes can be.  This may change.}
+\end{funcdesc}
+
 \begin{funcdesc}{xrange}{start\, end\, step}
 This function is very similar to \code{range()}, but returns an
 ``xrange object'' instead of a list.  This is an opaque sequence type
index e6430be3ef34ee95fdea3d1f51a9d41762f1302a..731d344dbec2c17a96f412088e33cbe03787252e 100644 (file)
@@ -34,6 +34,14 @@ the built-in module \code{pwd}.  If the expansion fails, or if the
 path does not begin with a tilde, the path is returned unchanged.
 \end{funcdesc}
 
+\begin{funcdesc}{expandvars}{p}
+Return the argument with environment variables expanded.  Substrings
+of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are
+replaced by the value of environment variable \var{name}.  Malformed
+variable names and references to non-existing variables are left
+unchanged.
+\end{funcdesc}
+
 \begin{funcdesc}{isabs}{p}
 Return true if \var{p} is an absolute pathname (begins with a slash).
 \end{funcdesc}
index be8d9906dcb18e6f16afdee13333d2ffffba7c66..8c77e49aa153db72f816fc2775ab15dfea95735f 100644 (file)
@@ -300,7 +300,9 @@ characters are understood: \%, c, s, i, d, u, o, x, X, e, E, f, g, G.
 Width and precision may be a * to specify that an integer argument
 specifies the actual width or precision.  The flag characters -, +,
 blank, \# and 0 are understood.  The size specifiers h, l or L may be
-present but are ignored.  The ANSI features \code{\%p} and \code{\%n}
+present but are ignored.  The \code{\%s} conversion takes any Python
+object and converts it to a string using \code{str()} before
+formatting it.  The ANSI features \code{\%p} and \code{\%n}
 are not supported.  Since Python strings have an explicit length,
 \code{\%s} conversions don't assume that \code{'\\0'} is the end of
 the string.
@@ -309,6 +311,19 @@ For safety reasons, huge floating point precisions are truncated;
 \code{\%f} conversions for huge numbers are replaced by
 \code{\%g} conversions.  All other errors raise exceptions.
 
+If the right argument is a dictionary (or any kind of mapping), then
+the formats in the string must have a parenthesized key into that
+dictionary inserted immediately after the \code{\%} character, and
+each format formats the corresponding entry from the mapping.  E.g.
+\begin{verbatim}
+    >>> count = 2
+    >>> language = 'Python'
+    >>> print '%(language)s has %(count)03d quote types.' % vars()
+    Python has 002 quote types.
+    >>> 
+\end{verbatim}
+In this case no * specifiers may occur in a format.
+
 Additional string operations are defined in standard module
 \code{string} and in built-in module \code{regex}.
 \index{string}
index 73bc1454b70ff88ced49ed0d9ee164e7fd1f68e1..ab4b03c98b52da83f8ad15d7b2d519ae8864915d 100644 (file)
@@ -355,6 +355,18 @@ its goal is to return a printable string.
 \end{verbatim}\ecode
 \end{funcdesc}
 
+\begin{funcdesc}{vars}{}
+Without arguments, return a dictionary corresponding to the current
+local symbol table.  With a module, class or class instance object as
+argument (or anything else that has a \code{__dict__} attribute),
+returns a dictionary corresponding to the object's symbol table.
+The returned dictionary should not be modified: the effects on the
+corresponding symbol table are undefined.%
+\footnote{In the current implementation, local variable bindings
+cannot normally be affected this way, but variables retrieved from
+other scopes can be.  This may change.}
+\end{funcdesc}
+
 \begin{funcdesc}{xrange}{start\, end\, step}
 This function is very similar to \code{range()}, but returns an
 ``xrange object'' instead of a list.  This is an opaque sequence type
index e6430be3ef34ee95fdea3d1f51a9d41762f1302a..731d344dbec2c17a96f412088e33cbe03787252e 100644 (file)
@@ -34,6 +34,14 @@ the built-in module \code{pwd}.  If the expansion fails, or if the
 path does not begin with a tilde, the path is returned unchanged.
 \end{funcdesc}
 
+\begin{funcdesc}{expandvars}{p}
+Return the argument with environment variables expanded.  Substrings
+of the form \samp{\$\var{name}} or \samp{\$\{\var{name}\}} are
+replaced by the value of environment variable \var{name}.  Malformed
+variable names and references to non-existing variables are left
+unchanged.
+\end{funcdesc}
+
 \begin{funcdesc}{isabs}{p}
 Return true if \var{p} is an absolute pathname (begins with a slash).
 \end{funcdesc}
index be8d9906dcb18e6f16afdee13333d2ffffba7c66..8c77e49aa153db72f816fc2775ab15dfea95735f 100644 (file)
@@ -300,7 +300,9 @@ characters are understood: \%, c, s, i, d, u, o, x, X, e, E, f, g, G.
 Width and precision may be a * to specify that an integer argument
 specifies the actual width or precision.  The flag characters -, +,
 blank, \# and 0 are understood.  The size specifiers h, l or L may be
-present but are ignored.  The ANSI features \code{\%p} and \code{\%n}
+present but are ignored.  The \code{\%s} conversion takes any Python
+object and converts it to a string using \code{str()} before
+formatting it.  The ANSI features \code{\%p} and \code{\%n}
 are not supported.  Since Python strings have an explicit length,
 \code{\%s} conversions don't assume that \code{'\\0'} is the end of
 the string.
@@ -309,6 +311,19 @@ For safety reasons, huge floating point precisions are truncated;
 \code{\%f} conversions for huge numbers are replaced by
 \code{\%g} conversions.  All other errors raise exceptions.
 
+If the right argument is a dictionary (or any kind of mapping), then
+the formats in the string must have a parenthesized key into that
+dictionary inserted immediately after the \code{\%} character, and
+each format formats the corresponding entry from the mapping.  E.g.
+\begin{verbatim}
+    >>> count = 2
+    >>> language = 'Python'
+    >>> print '%(language)s has %(count)03d quote types.' % vars()
+    Python has 002 quote types.
+    >>> 
+\end{verbatim}
+In this case no * specifiers may occur in a format.
+
 Additional string operations are defined in standard module
 \code{string} and in built-in module \code{regex}.
 \index{string}