定义
代码对象 code object 是一段可执行的 Python 代码在 CPython 中的内部表示。
def test():
pass
co_list = []
L = dir(test.__code__)
for l in L:
if not l.startswith('__'):
co_list.append(l)
print(co_list)
| 属性 | 描述 |
|---|---|
| co_argcount | number of arguments (not including keyword only arguments, * or ** args) |
| co_code | string of raw compiled bytecode |
| co_cellvars | tuple of names of cell variables (referenced by containing scopes) |
| co_consts | tuple of constants used in the bytecode |
| co_filename | name of file in which this code object was created |
| co_firstlineno | number of first line in Python source code |
| co_flags | bitmap of CO_* flags, read more here |
| co_lnotab | encoded mapping of line numbers to bytecode indices |
| co_freevars | tuple of names of free variables (referenced via a function’s closure) |
| co_kwonlyargcount | number of keyword only arguments (not including ** arg) |
| co_name | name with which this code object was defined |
| co_names | tuple of names of local variables |
| co_nlocals | number of local variables |
| co_stacksize | virtual machine stack space required |
| co_varnames | tuple of names of arguments and local variables |












网友评论