See the code directly:
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #@Time: 2018/07/25 10:144 5 6 defAdd (x=0, Y=1):7 """8 add input args x and Y.9 :p Aram x:Ten :p Aram y: One : return:x + y A """ - returnX +y - the - if __name__=='__main__': - Printdir (add) -Attr_name_list = [ + 'func_closure','Func_code', - 'Func_defaults','func_dict', + 'Func_doc','func_globals', A 'Func_name' at ] - forAttr_nameinchattr_name_list: - PrintAttr_name.ljust (15),':', GetAttr (Add, Attr_name) - Print 'Func_code_filename:', Add.func_code.co_filename
The results are as follows: Gets the function name and file location: Func_name, Func_code.co_filename.
1 [' __call__ ', ' __class__ ', ' __closure__ ', ' __code__ ', ' __defaults__ ', ' __delattr__ ', ' __dict__ ', ' __doc__ ', ' __ Format__ ', ' __get__ ', ' __getattribute__ ', ' __globals__ ', ' __hash__ ', ' __init__ ', ' __module__ ', ' __name__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' func_closure ', ' Func_code ', ' func_defaults ', ' func_dict ', ' func_doc ', ' func_globals ', ' func_name ']2 Func_closure:none3Func_code: <code object Add at 0000000001cefe30, file"d:/users/14/pycharmprojects/ias/shapan/test_func.py", Line 6>4Func_defaults: (0, 1)5 func_dict: {}6 Func_doc:7 add input args x and Y.8:paramx:9:paramy:Ten:return: X +y One AFunc_globals: {' __builtins__ ': <module ' __builtin__ ' (built-inch), ' __file__ ': ' d:/users/14/pycharmprojects/ias/shapan/test_func.py ', ' attr_name ': ' func_globals ', ' __package__ ': None, ' Add ': <functionAdd at 0x0000000002615ac8>, ' attr_name_list ': [' func_closure ', ' func_code ', ' func_defaults ', ' func_dict ', ' func_doc ', ' func_globals ', ' func_ ' Name '], ' __name__ ': ' __main__ ', ' __doc__ ': None} - Func_name:add -func_code_filename:d:/users/14/pycharmprojects/ias/shapan/test_func.py
Several properties of Python functions func_name, Func_code, etc.