I have just read the following article: 
http://effbot.org/zone/python-objects.htm
(thanks to a link on Kent's site). It is very good, I really recommend it.

Still, a short passage has troubled my model about object names:
"The names are a bit different — they’re not really properties of the object, and the object itself doesn’t know what it’s called.
An object can have any number of names, or no name at all.
Names live in namespaces (such as a module namespace, an instance namespace, a function’s local namespace)."

What I guess: The second and third sentence seem to refer to variable names; meaning that objects 'live their life' whatever the number of variables (0, 1 or more) that point to them. These (variable) names are independant of the object -- and conversely. Now, the first sentence contradicts all what I thought I know on the topic! For me, not only /many/ types of objects have names, but they know about it, and these names are *really* bound to the object -- not to a variable pointing at it. Try the following:

def smeagol():
        pass
print smeagol.__name__  # --> 'smeagol'
gollum = smeagol
print gollum.__name__   # --> 'smeagol'

clear enough ;-)

I have the impression that what the article says applies to traditional built-in, non-object, data or values (or to the so-called C++ "data object"). In fact, even if types and classes are unified, even if values are object in Python, well, maybe some kinds of objects must remain different of others. Because there is a difference of nature. My model is that there is still a difference between 'real' values and 'real' objects.

Values are things ordinary used to described a quality or property: bools, ints, strings... These things have no names. They have value representations instead. To access the integer usually written '1' or 'one', I need no name: I will use a conventional representation that happens to be '1' and is also used as its __repr__. When I write "a=1", I create a variable which is bound to 1 which name is 'a'. But 'a' has nothing to do with 1.
print dir(1)
[..., '__repr__', ...] # no name

Now, 'real' objects, that we usually call class instances, that fit well in a model as parts of a system, have no representation. So that they need names: how could I access smeagol, once created, if it had no name? On the other hand, such objects have no value. I mean no "natural" value. I can simulate a value for an instance by implementing several __xxx__ methods such as __eq__ (there may be a global __value__ method, I would love it).

This distinction between representation for values and names for (other) object is not a python idiom. I think it simply can't be else, values are simply something different.

Denis

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to