Feature request: String-inferred names
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Dec 4 10:24:42 EST 2009
Brad Harms a écrit :
> On Fri, 04 Dec 2009 18:05:03 +1100, Ben Finney wrote:
(snip)
>>> 2.) Attributes whose values are determined or assigned dynamically by
>>> indirectly calling a function (like properties and instancemethods)
>> Yes, the term “property” seems to do what you want.
>
> I wasn't asking what you call any object or any /kind/ of object. I was
> asking for a term (noun?) that describes the WAY the object is accessed
> as an attribute of an instance, with the connotation that the value of
> the attribute would be calculated dynamically (by calling a function) at
> the time the attribute was accessed.
Then you definitly want "computed attribute" - which is quite standard
OO terminology FWIW.
(snip - Ben, I think you shouldn't have tred to teach your grandmother
how to suck eggs <g>)
> Also note the fact that Foo.spam is an _instancemethod_ object and not
> just a function, even though it was defined as "just a function" in the
> class body. That's because function objects are descriptors as well; it
> lets them produce unbound instancemethods. I'm not precisely sure how
> this works,
class function(object):
def __get__(self, instance, cls):
if instance:
assert isinstance(instance, cls)
return boundmethod(instance, cls)
else
return unboundmethod(cls)
> though. I think it only happens when the metaclass of a class
> processes the functions in the class block.
Nope, this is totally unrelated.
class Foo(object):
def __init__(self, bar):
self.bar = 42
def baaz(obj, whatever):
print obj.bar, whatever
Foo.baaz = baaz
f= Foo()
f.baaz("is the answer")
>>> 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.
>> This is a “class attribute” as distinct from an “instance attribute”.
>>
>
> I know it's called that, but I was talking more about the fact of it
> being accessed through an instance of the class rather than
Except for descriptors, this doesn't make much difference difference.
More information about the Python-list
mailing list