def index(self):

Tim Roberts timr at probo.com
Wed Dec 20 00:51:28 EST 2006


Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
>
>Gert Cuykens a écrit :
>>> FWIW, the first version raises an exception (unless of course the name
>>> 'index' is already bound in the enclosing scope). And the second won't
>>> probably work as expected with CherryPy.
>> 
>> <code>
>> class HelloWorld:
>> def index(self):
>>  return "Hello world!"
>> index.exposed = True #DOOOOOOH!
>
>And the winner is....
>
>> </code>
>
>The whole thing, I guess. While Python is quite easy to get started 
>with, there are a few gotchas. You're above snippet should be:
>
>class HelloWorld(object):
>     def index(self):
>         return "Hello World"
>     index.exposed = True

Many people find it more readable to write that as:

class HelloWorld(object):
    @cherrypy.exposed
    def index(self):
       return "Hello World"

I haven't decided yet.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list