Define self.something in def __call__ vs def something():

I have always used:

def something():
    return "something"

and ${view/something) in

Using bob templates (plonecli) to add a browser view it adds a

def __call__(self):
    # Implement your own actions:
    self.msg = _(u'A small message')

Is this approache "better" (faster?) than the other ?

It does not really matter. I prefer methods (or @property decorated methods) as well. If you want to have it faster:
use ${python:view.something()} since TALES has some significant overhead.

1 Like


In this particular case:

class View(...):
     msg = _(u'A small message')

is good as well.

But I agree with @jensens, property are IMO better than defining an instance variable.

Unless you add a property setter, properties cannot be changed and tracking changed instance variable in the code is a major pain.

1 Like