美文网首页
代码对象 code object 与 __code__ 属性

代码对象 code object 与 __code__ 属性

作者: huashen_9126 | 来源:发表于2020-04-20 23:45 被阅读0次

定义

代码对象 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

参考资料:
https://blog.csdn.net/jpch89/article/details/86764245

相关文章

  • 代码对象 code object 与 __code__ 属性

    定义 代码对象 code object 是一段可执行的 Python 代码在 CPython 中的内部表示。 属性...

  • Djnago - ORM操作

    ORM:关系对象映射。Object Relation Mapping.数据库与代码: 主流都是Code first...

  • 判断内置对象

    判断内置对象 代码 利用对象的构造函数的 name 属性来判断对象类型 借调 Object 的 toString ...

  • Dart语言超级父类之Object

    Object* 构造方法* 属性* 方法* 操作符* 代码 Object Dart语言和Java一样,都是面向对象...

  • Object.prototype

    Object.prototype属性表示Object的原型对象 Object.prototype 属性的属性特征:...

  • 对象和继承

    JavaScript中对象的创建方式有以下几种: object 构造函数 缺点:动态添加属性,代码量大 对象字面量...

  • javascript遍历

    ## 对象遍历 // Object对象属性 Object.prototype.userProp = 'userPr...

  • React 省市区选择控件封装

    接口数据 代码 参考:JS Object 对象中删除属性[https://blog.csdn.net/zhaozh...

  • iOS开发_运行时的简单使用

    动态添加属性/*产生关联,让某个对象(name)与当前对象的属性(name)产生关联参数1: id object ...

  • ES Object

    属性简单表达 属性名表达式 对象做属性名时 对象比较 Object.assign() Object.assign拷...

网友评论

      本文标题:代码对象 code object 与 __code__ 属性

      本文链接:https://www.haomeiwen.com/subject/pbfeihtx.html