How to fully disassemble Python source

前端 未结 2 1590
被撕碎了的回忆
被撕碎了的回忆 2021-02-03 13:47

I have been playing with the dis library to disassemble some Python source code, but I see that this does not recurse into functions or classes:

imp         


        
2条回答
  •  南旧
    南旧 (楼主)
    2021-02-03 14:35

    Import the file as a module and call dis.dis() on that module.

    import dis
    import test
    
    dis.dis(test)
    

    You can also do this from the command-line:

    python -m dis test.py
    

    Quoting from the documentation for dis.dis:

    For a module, it disassembles all functions.

    Edit: As of python 3.7, dis.dis is recursive.

提交回复
热议问题