Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Manolo =?iso-8859-1?Q?Mart=EDnez?= Newsgroups: comp.lang.python Subject: Re: Is vars() the most useless Python built-in ever? Date: Tue, 1 Dec 2015 09:44:16 +0100 Lines: 25 Message-ID: References: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.uni-berlin.de knQohkYV4gAdl+YNOesSLAKXnPaPPzYpnK2VXq/FqDig== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'args': 0.04; 'subject:Python': 0.05; 'bits': 0.07; 'main()': 0.07; 'true)': 0.07; 'cc:addr:python-list': 0.09; 'err:': 0.09; 'flush': 0.09; 'url:github': 0.09; 'def': 0.13; 'main():': 0.16; 'podcast': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:ever': 0.16; 'subject:most': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'exists.': 0.22; 'function:': 0.22; 'parse': 0.22; 'cheers,': 0.22; 'trying': 0.22; 'cc:no real name:2**0': 0.22; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'function': 0.28; 'thread,': 0.29; "i'm": 0.30; 'code': 0.30; 'probably': 0.31; 'anyone': 0.32; 'language.': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'file': 0.34; 'except': 0.34; 'newer': 0.35; 'skip:p 30': 0.35; 'skip:{ 10': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'why': 0.39; 'whatever': 0.39; 'does': 0.39; 'subject:the': 0.39; 'subject:-': 0.39; 'some': 0.40; 'skip:u 10': 0.61; 'judge': 0.66; 'oldest': 0.66; 'received:82.223': 0.84 Content-Disposition: inline In-Reply-To: <565cf141$0$1612$c3e8da3$5496439d@news.astraweb.com> User-Agent: Mutt/1.5.24 (2015-08-30) 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:99778 On 12/01/15 at 12:00pm, Steven D'Aprano wrote: > I'm trying to understand why vars() exists. Does anyone use it? Well, I have this little podcast aggregator (https://github.com/manolomartinez/greg) that I and a bunch of other people use. I started writing it some years ago, and the code is a bit of a palimpsest, newer functionality reflecting my (somewhat) better understanding of the language. One of the oldest bits is this main() function: def main(): # parse the args and call whatever function was selected try: args = parser.parse_args(sys.argv[1:]) args.func(vars(args)) except AttributeError as err: if str(err) == "\'Namespace\' object has no attribute \'func\'": parser.print_help() else: print("Something has gone wrong: {}".format(err), file = sys.stderr, flush = True) To judge by this thread, this is probably wrong/noobish? Cheers, Manolo