MCPcopy Create free account
hub / github.com/ipython/ipython / extract_vars

Function extract_vars

IPython/utils/frame.py:23–53  ·  view source on GitHub ↗

Extract a set of variables by name from another frame. Parameters ---------- *names : str One or more variable names which will be extracted from the caller's frame. depth : integer, optional How many frames in the stack to walk when looking for your variabl

(*names,**kw)

Source from the content-addressed store, hash-verified

21#-----------------------------------------------------------------------------
22
23def extract_vars(*names,**kw):
24 """Extract a set of variables by name from another frame.
25
26 Parameters
27 ----------
28 *names : str
29 One or more variable names which will be extracted from the caller's
30 frame.
31
32 depth : integer, optional
33 How many frames in the stack to walk when looking for your variables.
34 The default is 0, which will use the frame where the call was made.
35
36
37 Examples
38 --------
39 ::
40
41 In [2]: def func(x):
42 ...: y = 1
43 ...: print(sorted(extract_vars('x','y').items()))
44 ...:
45
46 In [3]: func('hello')
47 [('x', 'hello'), ('y', 1)]
48 """
49
50 depth = kw.get('depth',0)
51
52 callerNS = sys._getframe(depth+1).f_locals
53 return dict((k,callerNS[k]) for k in names)
54
55
56def extract_vars_above(*names):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected