Run the function only in a specific context
Project description
contextif: run the function only in a specific context
Sometimes we may need to run a function only if it happens in a strictly defined context. In this case, we can use this mini library.
Install it:
pip install contextif
And use:
from contextif import state
with state:
state(print, 'hello,', 'world!') # It will be printed.
state(print, "it's me, Mario!") # It won't.
Using state
as a function, you can pass another function and arguments to it there. It will be called only if it happens in a context created also using state
. The function will not be called out of context.
For convenience, after the first import of state
, this variable becomes builtin and you can access it in other modules of your program without importing.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
contextif-0.0.5.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for contextif-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 402ddae000fc743eafd9fbba2b4b2e70df2d18883a238731981532a6c4a9ea15 |
|
MD5 | 07bb48bf6154d30e0833a05c1a3dc9a9 |
|
BLAKE2b-256 | c85663bc357e214e429aa44716da395575e84ba23f363a042e6234401015d659 |