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:
#!/usr/bin/env python3
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.3.tar.gz
(2.1 kB
view details)
Built Distribution
File details
Details for the file uplevel-0.0.3.tar.gz
.
File metadata
- Download URL: uplevel-0.0.3.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 | be54f291426aa2515e229b5d10d0dc5f0c2cec82aa2fe9e4b9987b153b654600 |
|
MD5 | 13672fcf47f79b9ab8ebf621ebb324ea |
|
BLAKE2b-256 | fef3803c1fc3aa29c4f11fc850ec14f2c9e2b2bdda7a054a79ec1ab6e631f4e4 |
File details
Details for the file uplevel-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: uplevel-0.0.3-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 | f0ff83de9b5374bd2b3b9764c5339964e54b6e14b8ad59bc50c0c420d78aaaca |
|
MD5 | 2c9092227977636cdb8bcce39c7b2dce |
|
BLAKE2b-256 | 2bf25915c655aa466acaaca0cb17b4a1d89fcdcb00ab0aaf1ffada17743bf95b |