tempvars API¶
-
class
tempvars.
TempVars
(names=None, starts=None, ends=None, restore=True)¶ Context manager for handling temporary variables at the global scope.
WILL NOT WORK PROPERLY unless used as a context manager!!
CAN ONLY BE USED at global scopes (Python/IPython REPL, Jupyter notebook, etc.)
Parameters: - names –
list
ofstr
- Variables will be treated as temporary if their names test equal to any of these items. - starts –
list
ofstr
- Variables will be treated as temporary if their names start with any of these patterns (tested with.startswith(starts[i])
). - ends –
list
ofstr
- Variables will be treated as temporary if their names end with any of these patterns (tested with.endswith(ends[i])
). - restore –
bool
- IfTrue
, any variables hidden from the namespace upon entry into the with suite are restored to the namespace upon exit. IfFalse
, no variables are restored.
The
TempVars
instance can be bound in the with statement for access to stored variables, etc.:>>> with TempVars(names=['abcd']) as tv: ... pass
See the usage examples page for more information.
Class Members
These objects are accessible via the instance bound as part of the with statement (
tv
from the above snippet). All are constructed usingattr.ib()
.-
starts
¶ list
ofstr
- All passed.startswith
matching patterns.
-
restore
¶ bool
flag indicating whether to restore the prior namespace contents. Can be changed within the with suite.
- names –