Python Decorators

2011-04-04 Thread cootetom
Hi all, not exactly a django question but here goes... I'm trying to implement a decorator with one positional argument and one keyword argument. My wrapper function gets the positional argument just fine but the keyword argument throws an error "NameError: name 'as_string' is not defined." Code i

RE: Python Decorators

2011-04-05 Thread Chris Matthews
Chris -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of cootetom Sent: 04 April 2011 15:31 To: Django users Subject: Python Decorators Hi all, not exactly a django question but here goes... I'm trying to implement a decorator

Re: Python Decorators

2011-04-06 Thread Jonathan S
Your code looks perfect. Following does print 'True'. def widget(widget_switch, as_string=False): def decorator(func): def wrapper(*args, **kwargs): # logic in here can access the value of 'widget_switch' but 'as_string' is not defined? print as_string

Re: Python Decorators

2011-04-06 Thread cootetom
Yeah it's really odd. Since I posted I did the test that you've just shown and it's works fine. As soon as I put the same decorator on a django view function the as_string parameter is not defined in the wrapper. It's baffled me! On Apr 6, 10:48 am, Jonathan S wrote: > Your code looks perfect.