gpt4 book ai didi

python - 有人可以说明 python 名称修改的过程吗?

转载 作者:太空狗 更新时间:2023-10-30 01:30:43 27 4
gpt4 key购买 nike

doc

Private name mangling: When an identifier that textually occurs in a class definition begins with two or more underscore characters and does not end in two or more underscores, it is considered a private name of that class. Private names are transformed to a longer form before code is generated for them.

我试图更好地理解这个要生成的 Python 代码的过程。

由什么产生? Python 解释器?

生成什么?字节码?

这个数字是否适用这个程序?

enter image description here

谁能更详细地说明这个过程?

最佳答案

你让我很好奇,所以你让我查了一下。首先,当您查看生成的字节码时,它已经使用了 STORE_NAME。带有“损坏的”名称。

谁做的,什么时候做的? https://github.com/python/cpython/blob/master/Python/compile.c保留答案:

This file compiles an abstract syntax tree (AST) into Python bytecode.

对应的函数是_Py_Mangle (“名称修改:__private 变为 _classname__private。”)

关于python - 有人可以说明 python 名称修改的过程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57885720/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com