Is vars() the most useless Python built-in ever?
eryk sun
eryksun at gmail.com
Tue Dec 1 02:22:30 EST 2015
On Mon, Nov 30, 2015 at 7:00 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Either way, vars() doesn't solve the problem. What problem does it solve?
vars() used to be the way to list local variables.
>From 4 May 1994, Python 1.0.2 [1]:
vars() returns a dictionary containing the local variables;
vars(m) returns a dictionary containing the variables of
module m. Note: dir(x) is now equivalent to
vars(x).keys().
>From 13 October 1995, Python 1.3 [2]:
Two new built-in functions, "globals()" and "locals()",
provide access to dictionaries containming [sic] current
global and local variables, respectively. (These
augment rather than replace "vars()", which returns the
current local variables when called without an argument,
and a module's global variables when called with an
argument of type module.)
[1]: https://hg.python.org/cpython/file/v1.3/Misc/HISTORY#l386
[2]: https://hg.python.org/cpython/file/v1.3/Misc/NEWS#l55
More information about the Python-list
mailing list