\ingroup python_builtins Return a dictionary representing the global variables in the current execution frame, or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded).
| 1757 | /// Return a dictionary representing the global variables in the current execution frame, |
| 1758 | /// or ``__main__.__dict__`` if there is no frame (usually when the interpreter is embedded). |
| 1759 | inline dict globals() { |
| 1760 | #if PY_VERSION_HEX >= 0x030d0000 |
| 1761 | PyObject *p = PyEval_GetFrameGlobals(); |
| 1762 | return p ? reinterpret_steal<dict>(p) |
| 1763 | : reinterpret_borrow<dict>(module_::import("__main__").attr("__dict__").ptr()); |
| 1764 | #else |
| 1765 | PyObject *p = PyEval_GetGlobals(); |
| 1766 | return reinterpret_borrow<dict>(p ? p : module_::import("__main__").attr("__dict__").ptr()); |
| 1767 | #endif |
| 1768 | } |
| 1769 | |
| 1770 | PYBIND11_NAMESPACE_BEGIN(detail) |
| 1771 | /// Generic support for creating new Python heap types |