Another try at Python's selfishness

Donn Cave donn at u.washington.edu
Thu Feb 2 20:32:58 EST 2006


In article <1138926741.052843.169270 at z14g2000cwz.googlegroups.com>,
 n.estner at gmx.de wrote:
> >    write(sys.stdin, split(read(open(file, 'r')))[0])
> 
> So, if I got you right, the interpreter would have to interpret this
> line like this:
> 1. Evaluate the first parameter of the first function (sys.stdin)
> 2. Look up the attribute "write" in this object
> 3. evaluate the first parameter of the split function ->
> 4. evaluate the first parameter of the read function ->
> 5. evaluate file (I guess this is a local string variable?)
> 6. try attribute lookup "open" on the string
> 7. fail -> call the global "open" function
> 8. lookup "read" in that object, call it
> 9. attribute lookup "split" on the returned object
> 10. call __getitem__(0)
> 11. pass the parameters to the write function from (1)
> 
> Is this correct?
> My main problems are that you have to "guess" at step 6/7, and that the
> order of evaluation makes me a little dizzy ;-) Also, member functions
> seem to "shadow" global ones, what if I wanted to use some global
> "split" function I've written myself instead of the string's one. If I
> was mean, I'd ask you what this one does:
>   class A:
>     def test(self, this): return 1
>   class B:
>     def test(this, self): return 2
>   test(self=A(), this=B())

That usage (self is second parameter to B.test) is bound
to cause trouble in general, but in this case doesn't have
any effect I can see.  The function call "test" would be
resolved from its first parameter, instance of A, and that
function would return 1.  One of us is missing something
here, could be me.

> 
> The current call syntax at least can be read from left-to-right, and
> you always know whether you call a member function or a global one.

That's exactly the problem, it doesn't read from left to right,
because we swap back and forth between function(parameter and
parameter.function notation.  It only works if you don't have
to mix the two.  I'm saying, pick one and use it consistently.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list