Documented new built-in function vars().

Documented new formatting features: %s takes any type, and
'%(key)format' % dictionary.
Documented posixpath.expandvars().
This commit is contained in:
Guido van Rossum 1994-04-21 10:32:28 +00:00
parent 590b289672
commit 1738311dab
6 changed files with 72 additions and 2 deletions

View File

@ -355,6 +355,18 @@ its goal is to return a printable string.
\end{verbatim}\ecode \end{verbatim}\ecode
\end{funcdesc} \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} \begin{funcdesc}{xrange}{start\, end\, step}
This function is very similar to \code{range()}, but returns an This function is very similar to \code{range()}, but returns an
``xrange object'' instead of a list. This is an opaque sequence type ``xrange object'' instead of a list. This is an opaque sequence type

View 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. path does not begin with a tilde, the path is returned unchanged.
\end{funcdesc} \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} \begin{funcdesc}{isabs}{p}
Return true if \var{p} is an absolute pathname (begins with a slash). Return true if \var{p} is an absolute pathname (begins with a slash).
\end{funcdesc} \end{funcdesc}

View 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 Width and precision may be a * to specify that an integer argument
specifies the actual width or precision. The flag characters -, +, specifies the actual width or precision. The flag characters -, +,
blank, \# and 0 are understood. The size specifiers h, l or L may be 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, are not supported. Since Python strings have an explicit length,
\code{\%s} conversions don't assume that \code{'\\0'} is the end of \code{\%s} conversions don't assume that \code{'\\0'} is the end of
the string. 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{\%f} conversions for huge numbers are replaced by
\code{\%g} conversions. All other errors raise exceptions. \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 Additional string operations are defined in standard module
\code{string} and in built-in module \code{regex}. \code{string} and in built-in module \code{regex}.
\index{string} \index{string}

View File

@ -355,6 +355,18 @@ its goal is to return a printable string.
\end{verbatim}\ecode \end{verbatim}\ecode
\end{funcdesc} \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} \begin{funcdesc}{xrange}{start\, end\, step}
This function is very similar to \code{range()}, but returns an This function is very similar to \code{range()}, but returns an
``xrange object'' instead of a list. This is an opaque sequence type ``xrange object'' instead of a list. This is an opaque sequence type

View 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. path does not begin with a tilde, the path is returned unchanged.
\end{funcdesc} \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} \begin{funcdesc}{isabs}{p}
Return true if \var{p} is an absolute pathname (begins with a slash). Return true if \var{p} is an absolute pathname (begins with a slash).
\end{funcdesc} \end{funcdesc}

View 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 Width and precision may be a * to specify that an integer argument
specifies the actual width or precision. The flag characters -, +, specifies the actual width or precision. The flag characters -, +,
blank, \# and 0 are understood. The size specifiers h, l or L may be 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, are not supported. Since Python strings have an explicit length,
\code{\%s} conversions don't assume that \code{'\\0'} is the end of \code{\%s} conversions don't assume that \code{'\\0'} is the end of
the string. 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{\%f} conversions for huge numbers are replaced by
\code{\%g} conversions. All other errors raise exceptions. \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 Additional string operations are defined in standard module
\code{string} and in built-in module \code{regex}. \code{string} and in built-in module \code{regex}.
\index{string} \index{string}