Python Glossary Русский

all Python 3inspectfunction

inspect.isframe()

stack and frames

Checks that an object is an execution frame (types.FrameType), the thing returned by currentframe() and sys._getframe().

Syntax

inspect.isframe(object) -> bool

An item of the stack() list is not a frame but a FrameInfo: isframe(inspect.stack()[0]) is False, and the frame itself sits in the .frame field. A function is not a frame either: a frame is created per call and lives while the function runs (or while something references it). The same mix-up breaks getouterframes() when given a FrameInfo instead of a frame.

Examples

import inspect
fi = inspect.stack(0)[0]
print(inspect.isframe(fi), inspect.isframe(fi.frame))  # → False True
print(inspect.isframe(inspect.currentframe()))  # → True
del fi

See also

Open in the full glossarydocs.python.orgReport an inaccuracy