On Mon, 11 Apr 2005 23:59:35 -0300, Gabriel Genellina <[EMAIL PROTECTED]> wrote:

At Thursday 7/4/2005 10:53, * William wrote:


For example, I'd like a way to get the symbol name for variable a above. Is there a function like "nameOF( a )"?



Maybe a Python hacker guru could say something, but AFAIK, once you get inside the function nameOF( a ), there is no way to tell where its argument came from. In the following example, I think there is no way to distinguish inside f if it was called with a or b as an argument, since both are simply names pointing to the same object



That's exactly right. When programming in Python, there is a very strict distinction between "objects" and "names that happen to be bound to objects". If you are coming from a C or C++ background, for example, think of every variable in Python as being a pointer or reference. An object that is being pointed to has absolutely no idea which variables point to it. Even the run-time library does not know. Consider this pseudo-C++ example.


   int& i;
   int& j;
   i = 3;
   j = i;

At this point, the constant "3" has no clue that two things point to it. If I pass "i" to a function, that function receives "3". It receives no knowledge about "i" or "j", and there is no way to trace it back.

That's the situation in Python. A function receives an object, not a name. While inside the function, the parameter name happens to be bound to that object, but it doesn't know what other (outside) names might be bound to that object.

(Actually, that's not entirely true: it knows HOW MANY names are bound to it, so it can do reference counting and garbage collection, but not WHICH names.)

--
- Tim Roberts, [EMAIL PROTECTED]
 Providenza & Boekelheide, Inc.

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to