python3精要(84)-字节码原理及分析(2)
生活随笔
收集整理的這篇文章主要介紹了
python3精要(84)-字节码原理及分析(2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下面代碼可輸出代碼對象的屬性:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #learnbytecode-2.py import platformdef sayHello():print("hello,world!") print("python Version:",end="") print(platform.python_version()) print("---------------------") codeAttributes=dir(sayHello.__code__) for codeAttr in codeAttributes:if "co_" in codeAttr: print(codeAttr,end=":")print(getattr(sayHello.__code__,codeAttr)) 運行代碼,輸出屬性結果如下: python Version:3.9.4 --------------------- co_argcount:0 co_cellvars:() co_code:b't\x00d\x01\x83\x01\x01\x00d\x00S\x00' co_consts:(None, 'hello,world!') co_filename:H:\learnpyad\learnPyAdvance\learnbc\learnbytecode-2.py co_firstlineno:6 co_flags:67 co_freevars:() co_kwonlyargcount:0 co_lnotab:b'\x00\x01' co_name:sayHello co_names:('print',) co_nlocals:0 co_posonlyargcount:0 co_stacksize:2 co_varnames:()總結
以上是生活随笔為你收集整理的python3精要(84)-字节码原理及分析(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL 查询速度慢与性能差的原因与解
- 下一篇: 前、后端分离权限控制设计与实现