def index(self):
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Wed Dec 20 06:46:03 EST 2006
Tim Roberts a écrit :
> 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"
So do I. But this breaks compatibility with older Python versions, and
is perhaps a bit confusing for someone that doesn't seem to really get
some basic Python stuffs like what 'self' is...
My 2 cents
More information about the Python-list
mailing list