Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100997

Re: how to get names of attributes

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
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 <mailman.74.1451486123.11925.python-list@python.org> (permalink)
References <n60gfk$b0t$1@dont-email.me> <n60jb6$hln$2@dont-email.me> <mailman.69.1451479806.11925.python-list@python.org> <n60mcc$rtp$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de HWbAZZ3kYIqA/8WRjKGYjwftMiDv8Rt18wukjdgvX3Aw==
Return-Path <rosuav@gmail.com>
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 <n60mcc$rtp$1@dont-email.me>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:100997

Show key headers only | View raw


On Thu, Dec 31, 2015 at 12:31 AM, Charles T. Smith
<cts.private.yahoo@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-30 11:51 +0000
  Re: how to get names of attributes Chris Angelico <rosuav@gmail.com> - 2015-12-30 22:58 +1100
  Re: how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-30 12:16 +0000
    Re: how to get names of attributes Chris Angelico <rosuav@gmail.com> - 2015-12-30 23:34 +1100
  Re: how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-30 12:40 +0000
    Re: how to get names of attributes Chris Angelico <rosuav@gmail.com> - 2015-12-30 23:50 +1100
      Re: how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-30 13:31 +0000
        Re: how to get names of attributes Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-30 14:16 +0000
        Re: how to get names of attributes Chris Angelico <rosuav@gmail.com> - 2015-12-31 00:45 +1100
    Re: how to get names of attributes Random832 <random832@fastmail.com> - 2015-12-30 12:04 -0500
    Re: how to get names of attributes Chris Angelico <rosuav@gmail.com> - 2015-12-31 09:26 +1100
  Re: how to get names of attributes Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-30 14:10 +0000
    Re: how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-30 14:50 +0000
  Re: how to get names of attributes Steven D'Aprano <steve@pearwood.info> - 2015-12-31 10:58 +1100
    Re: how to get names of attributes "Charles T. Smith" <cts.private.yahoo@gmail.com> - 2015-12-31 10:46 +0000

csiph-web