Access the value of a variable in a higher stack frame
Project description
Uplevel
Access the values of variables in the parent scope. This package provides two commands: upvar
and uplift
.
Installation
pip install uplevel
Usage
Here is a short example of how to use upvar
command:
from uplevel import upvar
def fib(stop: int, step: int = 0):
if step < 2:
result = 0 if step == 0 else 1
elif step <= stop:
previous = upvar(1, 'result') # result from previous iteration
preprevious = upvar(2, 'result') # and one iteration before
result = previous + preprevious
else:
return upvar(1, 'result')
return fib(stop, step + 1)
print(fib(20))
Here is another example for the uplift
command:
import re
from uplevel import uplift
def simplematch(regex, string):
results = re.match(regex, string)
uplift(1, 'match', results)
return results
if simplematch(r"[abc]+", "abc123"):
print(f"Matched: {match.group(0)}")
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
uplevel-0.0.4.tar.gz
(2.1 kB
view details)
Built Distribution
File details
Details for the file uplevel-0.0.4.tar.gz
.
File metadata
- Download URL: uplevel-0.0.4.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1c1f2ba43e5e063c676e3720d2145b4a449b04af1544842e8f3b0f88fe922db |
|
MD5 | f39a802c01467fffea0f0b7639780472 |
|
BLAKE2b-256 | 693cbc8a97405b37aeef08986f2e91ed83f1128b0f08e37f2e4f97a6cd726785 |
File details
Details for the file uplevel-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: uplevel-0.0.4-py3-none-any.whl
- Upload date:
- Size: 2.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | feef1c9c1a55f92caf8681c5a39efb5ca1e7e1a0304c1e337472504d86bb5417 |
|
MD5 | 8d0c5b8445042638059406c3cf801a79 |
|
BLAKE2b-256 | fef3f156538e7bafec328fe747d51c491e96db8404ae84b2f4e3ce6d54be0f4e |