Feature request: String-inferred names

Brad Harms fearsomedragonfly at gmail.com
Fri Dec 4 01:22:08 EST 2009


On Tue, 2009-12-01 at 16:58 +0100, Bruno Desthuilliers wrote:
> The Music Guy a écrit :
> (snip)
> > Lie Ryan, I think I see what you're saying about using __dict__ to add
> > members
> 
> No "members" in Python - only attributes.

> > to a class, but it's not quite the same. __dict__ is only for
> > attributes, NOT properties, methods, etc. which all come from the
> > class of an object rather than the object's __dict__.
> 
> properties and methods (well, functions actually) ARE attributes... of 
> the class object. And you can of course access the obj.__class__.__dict__
> 
> Just for the record...

When I say "member" I am using it as a general term that describes any
value that can be accessed (get, set, del) through an object. If the
object is referenced by a variable named `foo`, then by using `foo.name`
or one of the XXXattr functions, one can access the member of `foo`
called `name`. What's important to note, though, is that the term
"member" does not make any assumption about how `foo.name` is
implemented.

When I say "attribute," however, I am referring specifically to a member
of an object where the member's name is a key in the object's __dict__,
and the value is the one that is paired with that key.

Example:

class Foo(object):
    def __init__(self):
        self._x = 5

    @property
    def x(self):
        return self._x

    @x.setter
    def x(self,val):
        self._x = val

    def frob(self):
        print "I've been frobbed!"

foo = Foo()

foo._x     # Each of these is both a member and an attribute.
foo.y = 6 
foo.x      # Each of these is a member, but neither is an attribute.
foo.frob

To be perfectly precise, foo.y is only an attribute AFTER the assignment
has been performed. Before 6 is assigned, foo.y is only a "member" and
not an "attribute" because "y" does not yet exist as a key in foo's
__dict__.

Essentially, I just use "member" as a convenience term. I thought that
was the convention among the community, but evidently it isn't as widely
used as such as I thought. 

Anyway, it looks like the docs agree with you
(http://docs.python.org/glossary.html#term-attribute), so I'm not going
to argue. However, for the purpose of clean communication, I'd still
like to have terms that refer specifically to:

1.) "Regular" attributes, ie. those that are shortcuts to items in the
directly associated object's __dict__, 
2.) Attributes whose values are determined or assigned dynamically by
indirectly calling a function (like properties and instancemethods)
3.) Attributes that are read from an object with regular .dot syntax,
but are actually attributes (in the sense of #1 above) of the  __dict__
of the object's class.




More information about the Python-list mailing list