Hi, Is it possible at all to define a class in Python that can read name of variable it is assigned to on init?
>>> MyObject = SomeClass() >>> print(MyObject) 'MyObject' For this to work, SomeClass __init__ needs to know what variable name is currently waiting to be assigned. But at the time __init__ is executed, MyObject is not entered global or local space yet. I know that this is possible to do on AST level, but AST is inaccessible when program is running, so what is the corresponding structure to track that? (links to source are appreciated) 1. Is it possible to do this in CPython and PyPy? 2. Is it possible to do this in generic way? 3. Is there any stack of assignments? 3.1. Is this stack accessible? Thanks. -- anatoly t. _______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev