Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: Is vars() the most useless Python built-in ever? Date: Tue, 1 Dec 2015 01:22:30 -0600 Lines: 24 Message-ID: References: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de zK3e3a1PQKujxnPtQ+WSCwFr0mHG3rZ/Qc671YPRRfdA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; '[1]:': 0.09; '[2]:': 0.09; 'argument,': 0.09; 'variables,': 0.09; 'python': 0.10; 'argument': 0.15; 'variables': 0.15; '(these': 0.16; '1.0.2': 0.16; '1995,': 0.16; 'dictionaries': 0.16; "module's": 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:ever': 0.16; 'subject:most': 0.16; 'variables;': 0.16; 'wrote:': 0.16; '2015': 0.20; 'variables.': 0.22; 'header:In- Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; "doesn't": 0.26; 'equivalent': 0.27; 'message-id:@mail.gmail.com': 0.27; '1.3': 0.29; 'dictionary': 0.29; 'problem': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'replace': 0.35; 'problem.': 0.35; 'url:org': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'does': 0.39; 'subject:the': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'url:3': 0.60; 'provide': 0.61; '30,': 0.63; 'note:': 0.66; '7:00': 0.84; 'url:cpython': 0.84; 'url:v1': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=bfBbsceguRH4Xm0rvbPrwwDFTJ/ShR0Qnsol7f5nxLE=; b=dPCggcoIrxSbBYzC4uEJyDdihqXVbBSAorL71YdPwZCLGWnCO0fJNN4dZPftgRGhkx ZfQzaBUzBNazHyKLFJYAGyTtw1i0wkUO0dkWkg8C+msqUsQrwyY5xVGAmckua1cXDDJp 9xgouqvaEMRYpX5HFe6rLjTpCP/SvCl7NlpLkKdP4GUd8zKH+m9d1HmvsNjai44Nr5bI IAn5y8LRcKJqXMGb9mdHWPo1hLUh2KfiTeoTgGt55+jAuFt6CjH4dn3ia+c3oPVDIOZD ydKJVkt1gz4HWDKF09gdnQrBbu+u4AMKvH4+37qt1sjRW65eSd14MQ1CG9FMsa0iOjTG dIUA== X-Received: by 10.50.141.131 with SMTP id ro3mr24749300igb.74.1448954590319; Mon, 30 Nov 2015 23:23:10 -0800 (PST) In-Reply-To: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99771 On Mon, Nov 30, 2015 at 7:00 PM, Steven D'Aprano 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