Feature request: String-inferred names
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Fri Dec 4 04:00:42 EST 2009
On Fri, 04 Dec 2009 18:05:03 +1100, Ben Finney wrote:
> Brad Harms <fearsomedragonfly at gmail.com> writes:
...
>> 1.) "Regular" attributes, ie. those that are shortcuts to items in the
>> directly associated object's __dict__,
>
> I don't know what you mean by “shortcuts to items”. The names are looked
> up in dictionaries; where do shortcuts play a part?
>
> Try “instance attribute”, as distinct from “class attribute”.
Not all such attributes are actually found in instance.__dict__.
>>> class Example(object):
... __slots__ = 'spam'
...
>>> x = Example()
>>> y = Example()
>>> x.spam = 23
>>>
>>> x.__dict__['spam']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Example' object has no attribute '__dict__'
>>> x.spam
23
>>> y.spam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: spam
So it is possible to have per-instance attributes that don't live inside
the instance __dict__.
>> 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.
Or dynamic attributes returned by __getattr__ or __getattribute__.
--
Steven
More information about the Python-list
mailing list