Thomas, A ha! Now I feel all warm and fuzzy inside. It's nice to start the day with learning something new.
To be honest, the initial problem was that I didn't understand the meaning of '__all__', again probably from not working in the large with python. After posting, I went and had another go at understanding decorators. I think your second decorator example is the neatest one I have seen and it is quite obvious where the value of the decorator here is. You have used a minimal amount of code to solve a potentially major long term code maintenance problem. I will echo Karim here, a very elegant solution. On 29 July 2011 07:37, Thomas Rachel < nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de> wrote: > Am 28.07.2011 20:01 schrieb Ian Kelly: > > > The advantage of Thomas's decorator here is that it lets you place the >> denotation of whether a function is exported alongside its definition, >> whereas simply declaring the __all__ list forces you to separate them. >> It also avoids the problem of possibly mistyping the function's name >> in the list. >> > > Thank you. For the ones who do not like @__all__ because it might look > ugly, here is an alternative: > > __all__ = [] > > def export(obj): > __all__.append(obj.__name__) > return obj > > It is nearly the same, but without an extra class and with the more > readable > > @export > def func(): pass > > > Thomas > > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> >
-- http://mail.python.org/mailman/listinfo/python-list