On this page
inspect.currentframe
Prev: inspect.ClosureVars | Up: inspect | Next: inspect.EndOfBlock
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.currentframe
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import currentframe
Signature & Overview
inspect.currentframe()
Return the frame of the caller or None if this is not possible.
Usage
import inspect
frame = inspect.currentframe()
try:
assert frame is not None and frame.f_lineno > 0
finally:
del frame # avoid keeping reference cycles alive
Gotchas
- Always
del framewhen done: Keeping a frame reference in a local variable creates a reference cycle. Also returnsNoneon Python implementations without stack-frame support.
REPL Inspect
from inspect import currentframe
help(currentframe)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/ClosureVars Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/EndOfBlock Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib