Re: Getting lazy with decorators

2012-06-27 Thread Josh English
On Monday, June 25, 2012 11:57:39 PM UTC-7, Peter Otten wrote: > > > > There is nothing in the documentation (that I have found) that points to > > this solution. > > That's because I "invented" it. > Oh bother. The lines I completely overlooked were in your __getattr__ override. Boy is my fa

Re: Getting lazy with decorators

2012-06-26 Thread Peter Otten
Peter Otten wrote: >>>helpfunc = getattr(self, "do_" + name[5:]).help > > i. e. it looks for getattr(self, "do_help") which does exist and then Sorry that should be getattr(self, "do_done"). -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting lazy with decorators

2012-06-26 Thread Peter Otten
Josh English wrote: > On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: >> >> You cannot access a class instance because even the class itself doesn't >> exist yet. You could get hold of the class namespace with >> sys._getframe(), >> >> def add_help(f): >> exec """\ >> def help_

Re: Getting lazy with decorators

2012-06-25 Thread Josh English
On Sunday, June 24, 2012 1:07:45 AM UTC-7, Peter Otten wrote: > > You cannot access a class instance because even the class itself doesn't > exist yet. You could get hold of the class namespace with sys._getframe(), > > def add_help(f): > exec """\ > def help_%s(self): > f = getattr(self

Re: Getting lazy with decorators

2012-06-24 Thread Stefan H. Holek
On 24.06.2012, at 03:58, Josh English wrote: > I'm creating a cmd.Cmd class, and I have developed a helper method to easily > handle help_xxx methods. When I need custom help processing I tend to simply override do_help(). Stefan http://pypi.python.org/pypi/kmd -- Stefan H. Holek ste...@ep

Re: Getting lazy with decorators

2012-06-24 Thread Peter Otten
Josh English wrote: > I'm creating a cmd.Cmd class, and I have developed a helper method to > easily handle help_xxx methods. > > I'm trying to figure out if there is an even lazier way I could do this > with decorators. > > Here is the code: > * > import cmd > > > def add_

Getting lazy with decorators

2012-06-23 Thread Josh English
I'm creating a cmd.Cmd class, and I have developed a helper method to easily handle help_xxx methods. I'm trying to figure out if there is an even lazier way I could do this with decorators. Here is the code: * import cmd def add_help(func): if not hasattr(func, 'im_cl