def index(self):

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Dec 18 16:25:08 EST 2006


Gert Cuykens a écrit :
> Is there a difference between
> 
> <code>
> class HelloWorld:
> def index(self):
>  index.exposed = True
>  return "Hello world!"
> </code>
> 
> and
> 
> <code>
> class HelloWorld:
> def index(self):
>  self.exposed = True
>  return "Hello world!"
> </code>

Ask yourself what are the names 'index' and 'self' refering to in the 
context of this function, and you'll have the answer. And if you can't 
answer, then it may be time to learn Python...

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.






More information about the Python-list mailing list