How to get the source code of python function being decorated?

Peng Yu pengyu.ut at gmail.com
Fri Sep 16 15:19:54 EDT 2016


Hi, See the following example, I am not able to get the source code of
the actual function that does the calculation of partial_ratio. Does
anybody know what is the correct way of getting the source?

/tmp$ ./main.py
    @functools.wraps(func)
    def decorator(*args, **kwargs):
        if args[0] is None or args[1] is None:
            return 0
        return func(*args, **kwargs)

/tmp$ cat ./main.py
#!/usr/bin/env python
# vim: set noexpandtab tabstop=2 shiftwidth=2 softtabstop=-1 fileencoding=utf-8:

import fuzzywuzzy.fuzz
import inspect
print inspect.getsource(fuzzywuzzy.fuzz.partial_ratio)

-- 
Regards,
Peng



More information about the Python-list mailing list