No project description provided
Project description
ContextManaged Assign
This Python project provides a context manager for temporarily assigning a value to a variable or attribute. The original value is restored when the context is exited.
Usage
from contextmanaged_assign import assign
l = [1, 2, 3]
assert l[0] == 1
with assign("l[0]", 2):
assert l[0] == 2
assert l[0] == 1
Please note that assign cannot modify local variables themselves. For example, the following code will not work:
x = 1
with assign("x", 2):
assert x == 2 # AssertionError: 1 != 2
assert x == 1
Installation
Simply install the package using pip:
pip install contextmanaged-assign
Then import the assign function from the contextmanaged-assign module.
License
Project details
Release history Release notifications | RSS feed
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 contextmanaged_assign-0.1.0.tar.gz.
File metadata
- Download URL: contextmanaged_assign-0.1.0.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fb048178836a43313976d9f48d7e444b4d792fa0e1ce6950060419135c7cc1e
|
|
| MD5 |
160ca0b18c0a9c156a861d973cda4bbb
|
|
| BLAKE2b-256 |
73eee6b504910b1ed5df9363492f8bb85ae6f0689da152372542decaa9334f1c
|
File details
Details for the file contextmanaged_assign-0.1.0-py3-none-any.whl.
File metadata
- Download URL: contextmanaged_assign-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e12a26bbe0501dc4b498925dc2bc8b58fcd78fab0e3de1e8b75d822f6683866
|
|
| MD5 |
ed0f068ee15339d54e212eb817133777
|
|
| BLAKE2b-256 |
183886961657f6c95c41fab88103872bf86b38b7d6bf49d39fe7533152865b4e
|