[Tutor] Decorators revised
Mary Morris
marris1031 at gmail.com
Wed Jun 30 23:12:30 CEST 2010
I need help with the following task for my new job:
The code we're using is written in python, which I have never worked with
before.
Our AMS source code relies heavily on decorators.Things look something like
this:
@decomaker(argA, argB, ...)
def func(arg1, arg2, ...):
pass
which is the same as
func = decomaker(argA, argB, ...)(func)
and
@dec2
@dec1
def func(arg1, arg2, ...):
pass
func = dec2(dec1(func))
Or when implemented the second example looks like:
def dec1(func):
def new_func(arg1, arg2, ...):
... do something...
ret = func(arg1, arg 2, ...)
... do more things...
return ret
return new_func
My first task is that there is an issue with the name new_func. When the
program crashes, that is what shows up in the logs-which doesn't help debug
anything. I need to find out every decorator and make sure it has a
descriptive name. I was thinking I could write a simple script which would
parse through all of the source files and find decorators-maybe by looking
for the @ symbol? Then I could manually check to make sure it has a good
name. I was thinking I could copy the searching code from find_imports.py
(up to the startswith() calls) and print the list of decorators found and
which files that they're in. What I want to do is use a find() for the @dec
maybe.... I also don't know how to parse out everything that's not the
name- at dec(arg1, arg2) should be "dec". I have never worked with python
before so I definitely need help with this task-any suggestions or examples
that would be helpful?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100630/c7713469/attachment-0001.html>
More information about the Tutor
mailing list