context¶
Functions¶
-
jnrbase.context.
chdir
(__path)[source]¶ Context handler to temporarily switch directories.
- Parameters
__path (
Path
) – Directory to change to- Yields
Execution context in
path
- Return type
AbstractContextManager
[+T_co]
-
jnrbase.context.
env
(**kwargs)[source]¶ Context handler to temporarily alter environment.
If you supply a value of
None
, then the associated key will be deleted from the environment.- Parameters
kwargs (
str
) – Environment variables to override- Yields
Execution context with modified environment
- Return type
AbstractContextManager
[+T_co]
Examples¶
>>> sorted(listdir('.')[:2])
['.travis.yml', 'README.rst']
>>> with chdir('doc'):
... sorted(listdir('.'))[:3]
['NEWS.rst', 'alternatives.rst', 'api']
>>> sorted(listdir('.')[:2])
['.travis.yml', 'README.rst']
>>> with env(SHELL='oi'):
... getenv('SHELL')
'oi'