__code__ 示例:
>>> def func(arg1,arg2):
... return arg1*arg2
...
>>> print dir(func.__code__)
['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
>>> print func.__code__.co_varnames
('arg1', 'arg2')
>>> print func.__code__.co_name
func
__code__拿到代码信息
最新推荐文章于 2022-03-08 14:23:26 发布