Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: how to get names of attributes Date: Thu, 31 Dec 2015 00:45:05 +1100 Lines: 43 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de HWbAZZ3kYIqA/8WRjKGYjwftMiDv8Rt18wukjdgvX3Aw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.02; 'cpython': 0.05; 'continuation': 0.07; 'cc:addr:python-list': 0.09; 'python': 0.10; 'output': 0.13; 'def': 0.13; 'thu,': 0.15; 'better?': 0.16; 'cls': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'skip:v 30': 0.20; '31,': 0.22; 'pass': 0.22; 'trying': 0.22; 'am,': 0.23; 'dec': 0.23; "haven't": 0.24; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'wonder': 0.27; 'message- id:@mail.gmail.com': 0.27; '2.6': 0.27; "skip:' 10": 0.28; 'indentation': 0.29; "i'm": 0.30; 'maybe': 0.33; 'class': 0.33; 'correctly': 0.34; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'skip:v 20': 0.38; 'version': 0.38; 'received:209': 0.38; 'log': 0.38; 'skip:p 20': 0.38; 'thank': 0.38; 'skip:o 20': 0.38; 'does': 0.39; 'your': 0.60; 'skip:u 10': 0.61; 'you.': 0.64; 'between': 0.65; 'restore': 0.70; 'gotten': 0.76; 'smith': 0.76; 'subject:get': 0.81; '2.7.': 0.84; 'chrisa': 0.84; 'filtered': 0.84; 'received:209.85.213.194': 0.84; 'to:none': 0.91; '(running': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rk5wmd89h5X2pV0w1f6E4wANYsAZKJ5ZUhh+JaRUJqc=; b=jgkgT65WDy7r6c1gEs0fkhdWg5NSXKIb92kC9n11ItqRkAO0WyBF8Unuyy9YeXrlzI SdTNpIuYgROXQ/ySDSoEWynczLhr5JKWLW+rEn0yWFgwhq/usTov7n1S7z2QfPF6pBQH 3K+xJuS+BS/7hqk63PeRaaa6tmuT7GsezsWu3WhRTGgIbT8fOPa8g80wVczl865L/2HK KFMDxoEBsgZYj1gSZZOAvKS6EnPIZ7hsxDEwmfuqeAFMze9KSQx6CX1mrFBZM0F0FpBS u/H580ylIqTI72JJVS3DeiYOJ8rklj92r+pDEhX09CSxh6Gnvo8HH7P2R6O6z+7+dQGn EgCA== X-Received: by 10.50.66.179 with SMTP id g19mr46320034igt.94.1451483105147; Wed, 30 Dec 2015 05:45:05 -0800 (PST) In-Reply-To: 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:100997 On Thu, Dec 31, 2015 at 12:31 AM, Charles T. Smith wrote: > Okay, thank you. I'm trying to understand your program. > > Unfortunately, I haven't gotten the same output you had, using python 2.6 > or 2.7. Maybe I haven't been able to restore the indentation correctly > after having been filtered through pan(1). > > I wonder what the difference is between vars() and items() What I sent you was a log of interactive Python, so there are prompts and continuation prompts. Here's a script version of the same thing (running under CPython 2.7): class X: pass class Y(X): pass class Z(Y): pass X.x=1 Y.y=2 Z.z=3 inst=Z() inst.i=4 def class_vars(old_style_class): v = {} for cls in old_style_class.__bases__: v.update(class_vars(cls)) v.update(vars(old_style_class)) return v def all_vars(old_style_inst): v = class_vars(old_style_inst.__class__) v.update(vars(old_style_inst)) return v print(all_vars(inst)) # {'i': 4, '__module__': '__main__', 'y': 2, 'x': 1, 'z': 3, '__doc__': None} Does that work better? ChrisA