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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contextif-0.0.5.tar.gz.
File metadata
- Download URL: contextif-0.0.5.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
927b7dc0b39945137dba63581416ca3c3ccb28ab2d49d61e30d386ae7d7732b7
|
|
| MD5 |
35f0cdd9330c32ebb805c6e3b1ac64f1
|
|
| BLAKE2b-256 |
86a09c607b4b15f77f224e3b43dd38014cd43c8c21db701dd990f318db32ffda
|
File details
Details for the file contextif-0.0.5-py3-none-any.whl.
File metadata
- Download URL: contextif-0.0.5-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
402ddae000fc743eafd9fbba2b4b2e70df2d18883a238731981532a6c4a9ea15
|
|
| MD5 |
07bb48bf6154d30e0833a05c1a3dc9a9
|
|
| BLAKE2b-256 |
c85663bc357e214e429aa44716da395575e84ba23f363a042e6234401015d659
|