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 –
listofstr- Variables will be treated as temporary if their names test equal to any of these items. - starts –
listofstr- Variables will be treated as temporary if their names start with any of these patterns (tested with.startswith(starts[i])). - ends –
listofstr- 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
TempVarsinstance 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 (
tvfrom the above snippet). All are constructed usingattr.ib().-
starts¶ listofstr- All passed.startswithmatching patterns.
-
restore¶ boolflag indicating whether to restore the prior namespace contents. Can be changed within the with suite.
- names –