why function got dictionary

Tim Roberts timr at probo.com
Fri Apr 18 08:55:28 CEST 2008


AlFire <spamgrinder.trylater at gmail.com> wrote:

>Diez B. Roggisch wrote:
>>>
>>> Q: why function got dictionary? What it is used for?
>> 
>> because it is an object, and you can do e.g.
>> 
>
>you mean an object in the following sense?
>
> >>>  isinstance(g,object)
>True
>
>where could I read more about that?

This is a very useful feature.  As just one example, the CherryPy web
server framework lets you define a class to handle one directory in a web
site, where each page is mapped to member functions.  However, you also
need to include support functions that should not be exposed as web pages.
To do that, you just add an "exposed" attribute to the function:

class MyWebPage:
    ...
    def index( self, ... ):
        pass
    index.exposed = 1

    def notExposed( self, ... ):
        pass

    def request( self, ... ):
        pass
    request.exposed = 1
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list