<dd><emclass="refcount return_borrowed_ref">回傳值:借用參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a>.</em><divclass="deprecated">
<p><spanclass="versionmodified deprecated">在 3.13 版之後被棄用: </span>Use either <aclass="reference internal" href="#c.PyEval_GetFrameLocals" title="PyEval_GetFrameLocals"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyEval_GetFrameLocals()</span></code></a> to obtain the same behaviour as calling
<aclass="reference internal" href="../builtins/functions.html#locals" title="locals"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">locals()</span></code></a> in Python code, or else call <aclass="reference internal" href="frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyFrame_GetLocals()</span></code></a> on the result
of <aclass="reference internal" href="#c.PyEval_GetFrame" title="PyEval_GetFrame"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyEval_GetFrame()</span></code></a> to access the <aclass="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">f_locals</span></code></a> attribute of the
currently executing frame.</p>
</div>
<p>Return a mapping providing access to the local variables in the current execution frame,
or <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code> if no frame is currently executing.</p>
<p>Refer to <aclass="reference internal" href="../builtins/functions.html#locals" title="locals"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">locals()</span></code></a> for details of the mapping returned at different scopes.</p>
<p>As this function returns a <aclass="reference internal" href="../glossary.html#term-borrowed-reference"><spanclass="xref std std-term">borrowed reference</span></a>, the dictionary returned for
<aclass="reference internal" href="../glossary.html#term-optimized-scope"><spanclass="xref std std-term">optimized scopes</span></a> is cached on the frame object and will remain
alive as long as the frame object does. Unlike <aclass="reference internal" href="#c.PyEval_GetFrameLocals" title="PyEval_GetFrameLocals"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyEval_GetFrameLocals()</span></code></a> and
<aclass="reference internal" href="../builtins/functions.html#locals" title="locals"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">locals()</span></code></a>, subsequent calls to this function in the same frame will update the
contents of the cached dictionary to reflect changes in the state of the local variables
rather than returning a new snapshot.</p>
<divclass="versionchanged">
<p><spanclass="versionmodified changed">在 3.13 版的變更: </span>As part of <spanclass="target" id="index-0"></span><aclass="pep reference external" href="https://peps.python.org/pep-0667/"><strong>PEP 667</strong></a>, <aclass="reference internal" href="frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyFrame_GetLocals()</span></code></a>, <aclass="reference internal" href="../builtins/functions.html#locals" title="locals"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">locals()</span></code></a>, and
<aclass="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">FrameType.f_locals</span></code></a> no longer make use of the shared cache
dictionary. Refer to the <aclass="reference internal" href="../whatsnew/3.13.html#whatsnew313-locals-semantics"><spanclass="std std-ref">What's New entry</span></a> for
<dd><emclass="refcount return_borrowed_ref">回傳值:借用參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a>.</em><p>Return the <aclass="reference internal" href="../glossary.html#term-attached-thread-state"><spanclass="xref std std-term">attached thread state</span></a>'s frame, which is <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code> if no frame is
currently executing.</p>
<p>另請見 <aclass="reference internal" href="threads.html#c.PyThreadState_GetFrame" title="PyThreadState_GetFrame"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyThreadState_GetFrame()</span></code></a>。</p>
<dd><emclass="refcount return_new_ref">回傳值:新的參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a> 自 3.13 版本開始.</em><p>Return a dictionary of the builtins in the current execution frame,
or the interpreter of the thread state if no frame is currently executing.</p>
<dd><emclass="refcount return_new_ref">回傳值:新的參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a> 自 3.13 版本開始.</em><p>Return a dictionary of the local variables in the current execution frame,
or <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code> if no frame is currently executing. Equivalent to calling
<p>To access <aclass="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">f_locals</span></code></a> on the current frame without making an independent
snapshot in <aclass="reference internal" href="../glossary.html#term-optimized-scope"><spanclass="xref std std-term">optimized scopes</span></a>, call <aclass="reference internal" href="frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyFrame_GetLocals()</span></code></a>
on the result of <aclass="reference internal" href="#c.PyEval_GetFrame" title="PyEval_GetFrame"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyEval_GetFrame()</span></code></a>.</p>
<dd><emclass="refcount return_new_ref">回傳值:新的參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a> 自 3.13 版本開始.</em><p>Return a dictionary of the global variables in the current execution frame,
or <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code> if no frame is currently executing. Equivalent to calling
<dd><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a>.</em><p>Return the name of <em>func</em> if it is a function, class or instance object, else the
<dd><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a>.</em><p>Return a description string, depending on the type of <em>func</em>.
Return values include "()" for functions and methods, " constructor",
" instance", and " object". Concatenated with the result of
<aclass="reference internal" href="#c.PyEval_GetFuncName" title="PyEval_GetFuncName"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyEval_GetFuncName()</span></code></a>, the result will be a description of