Python decorator syntax limitations

2010-01-18 Thread Jonathan S
Hi all, The following is what I want to do, but this results in a syntax error: @news_page('template.html').lookup(News, 'news_id', 'news') def view(request, group, news): pass What does work is the equivalent old way of doing decorating: def view(request, group, news): pass view = ne

Re: Python decorator syntax limitations

2010-01-18 Thread Jonathan S
Thanks a lot, all of you! This was really helpful. (or at least give me the inspiration I needed to finish it.) I'm sure this is a use case where most other options are less readable than the chain of methods in the decorator. In this use case, I had a lot of Django views to which access permissio

Replacing globals in exec by custom class

2010-12-08 Thread Jonathan S
Hi all, I wonder if anyone can explain some weird behaviour in Python. What I'm trying to do is to execute a string of python code through the 'exec' statement. I pass an instance of my Global class, which acts like a dict. By overriding the __getitem__ method, the Global should pretend that a glo

Re: Replacing globals in exec by custom class

2010-12-09 Thread Jonathan S
Thanks for your response! (And sorry about the syntax error, I forgot to test my code after cleaning up some debug statements before posting, the else should have been elif indeed.) It's very interesing, how Python works internally. According to a thread on the Python mailing list in 2002, it seem