function v. method

Bruno Desthuilliers onurb at xiludom.gro
Tue Jul 18 04:38:00 EDT 2006


danielx wrote:
> At first I was going to post the following:
> 
> <!-- beginning of my original post -->
> 
(snip)
> 
> <!-- end of my original post, with ending censored -->
> 
> but then I tried this:
> 
> 
>>>>res = Foo.__dict__['func']
>>>>res is dan
> 
> True
> 
> And it all started to make sense. The surprising thing turned out to be
> not so surprising: When the expression Foo.func gets evaluated, we get
> a method which is just a wrapper around dan. Therefore, f is not dan!
> This is still a little bit of magic,

FWIW, the function class implements the descriptor protocol... Here's
the "magic".

> which gets me thinking again about
> the stuff I self-censored. Since the dot syntax does something special
> and unexpected in my case,

"unexpected" ? Did you ever wondered how the instance or class was
passed as first arg when doing method calls ?

> why not use some more dot-magic to implement
> privates?

What for ? What makes you think we need language-inforced access
restriction ?

(snip)

> BTW, I am aware of Python's name mangling feature.

Name mangling is mainly here to protect from accidental overridding. The
 convention for implementation attributes is single-leading-underscore.


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list