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
Close
Hashes for contextmanaged_assign-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fb048178836a43313976d9f48d7e444b4d792fa0e1ce6950060419135c7cc1e |
|
MD5 | 160ca0b18c0a9c156a861d973cda4bbb |
|
BLAKE2b-256 | 73eee6b504910b1ed5df9363492f8bb85ae6f0689da152372542decaa9334f1c |
Close
Hashes for contextmanaged_assign-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e12a26bbe0501dc4b498925dc2bc8b58fcd78fab0e3de1e8b75d822f6683866 |
|
MD5 | ed0f068ee15339d54e212eb817133777 |
|
BLAKE2b-256 | 183886961657f6c95c41fab88103872bf86b38b7d6bf49d39fe7533152865b4e |