On 2015-04-21 16:38, Ben Finney wrote:
That hope is understandable.
Your "understanding" is appreciated.
It is also easy to be confused ....
So true, but with the help of "Python Tutors" things are being
rectified!
about why such a feature doesn't exist;
So why not arbitrary objects?
The answer is that functions, classes, and modules are all *defined*,
and (normally) have exactly one canonical name established at
definition
time.
Arbitrary objects are merely *instantiated*, without that definition
step. Quite commonly they are used with no name bound to them; so the
behaviour of most objects does not have ‘__name__’ in the API.
If you would like to make a class that has that attribute on all its
instances, feel free. But you need to figure out how the instance
detects its own name!
class LockeanThing:
""" An object that knows the name by which others refer to it.
"""
def __init__(self):
self.__name__ = ???
But I see what I think you and others have been trying to explain to
me: that the expression some_object.__name__, if it existed, would
indeed be schizophrenic since it would be an attribute of the object,
not the name(s) to which it is bound.
That's why I prefer to be clear that the binding operation is one-way
only.
A reference (such as a name) is bound to an object, the object is not
bound to the reference — indeed, the object knows nothing about that
relationship.
It's sinking in. Thank you.
ak
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor