You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In short: in recent Pythons, impossible, by design. This is probably a good thing.
In Python ≤ 3.6, as discussed on stupidpythonideas, there was PyFrame_LocalsToFast in the CPython C API, which could be accessed via ctypes. This no longer works in 3.7 and later (PEP 558).
The alternative of using inspect.stack() and mutating the f_locals attribute of the frame object doesn't work, either.
In short: in recent Pythons, impossible, by design. This is probably a good thing.
In Python ≤ 3.6, as discussed on stupidpythonideas, there was
PyFrame_LocalsToFast
in the CPython C API, which could be accessed viactypes
. This no longer works in 3.7 and later (PEP 558).The alternative of using
inspect.stack()
and mutating thef_locals
attribute of the frame object doesn't work, either.See also Everything in Python is mutable.
(This issue is intentionally left open to collect links to related reading.)
The text was updated successfully, but these errors were encountered: