Home > Programming, Python > Py Decorator

Py Decorator

Recently, I was reading some articles on Python decorator. It motives me since a phone interview.  Before that, I wasn’t paying much attention to it. But later one, I found it a very good tool to do the dynamic programming.

Below are some online sources that I collect, I try to make it more or like the Q-A style:

#Some good links:
– Decorator home: pypi.python.org/pypi/decorator
– Computing Thoughts: http://www.artima.com/weblogs/viewpost.jsp?thread=240808

#One example code for decorator used for logging information:

#Neat things to do with Python decorators – Ubuntu Forums

Q: How to show the help information defined in original function, after the function is decorated.
A: use functools.wraps() The Standard Library doc for functools (http://docs.python.org/library/functools.html)
Links=> http://stackoverflow.com/questions/1782843/python-decorator-problem-with-docstrings

Q: An example worthy understanding more
Links-> http://stackoverflow.com/questions/681953/python-class-decorator
Notes: The function like wrap the inner original function, with additional def-functions, it can most utilize the original function or class, but most likely work when initialization.
Another thing is that we need to discriminate the “decorator” and “sub-or-super-class structure”.

Q: oop – What is a metaclass in Python? – Stack Overflow
Links-> ; http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python

Q: Understanding Python decorators – Fantastic Answer
Links=> http://stackoverflow.com/questions/739654/understanding-python-decorators

Q: A well introduction of decorator
Link-> http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

Q: Is there some build-in functions can be used as decorator?
A: functools module contains some fucntions that can be used as decorators, but they aren’t built-ins.
As a side notes: we can find the list of Built-in functions at: Python glossary
Also PythonDecoratorLibrary may give some good examples for using of decorator

Q: Discussion on “a-ha this looks liek a job for decorator”
Links-> http://stackoverflow.com/questions/489720/what-are-some-common-uses-for-python-decorators
A: Good examples:Bruce Eckel on Decorators and Example : A Decorator-Based Build System

An example  that I wrote using decorator for dynamic programming.

Categories: Programming, Python
  1. May 14, 2011 at 10:09 PM

    Good points

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: