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.3.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for contextif-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eacc1baa7637737f57edf525171866e9b0218065cf55fb961771cc256e6c8721 |
|
MD5 | 319b9e40a41ce3649ae3dfe39573c917 |
|
BLAKE2b-256 | a3a596b1bacf52c67f7f04f2a50866d37eea45d603b83979b3ef4ee11797a164 |