Skip to main content

Uplevel

Access the values of variables in the parent scope. This package provides two commands: upvar and upset.

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 upset command. It provides the feature to inject a variable into a parent scope. This can be useful but it also might upset people who read this code.

import re
from uplevel import upset


def simplematch(regex, string):
    results = re.match(regex, string)
    upset(1, 'match', results)
    return results


if simplematch(r"[abc]+", "abc123"):
    print(f"Matched: {match.group(0)}")

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.5.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uplevel-0.0.5-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

Details for the file uplevel-0.0.5.tar.gz.

File metadata

  • Download URL: uplevel-0.0.5.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for uplevel-0.0.5.tar.gz
Algorithm Hash digest
SHA256 d4bb91572e25f127b0a84368c0a07dcee9a157dcfb405f160de4f9f59812118b
MD5 81fb6a8f741911ea6f76b6e4cd3cbdb2
BLAKE2b-256 36c0e05386ea73218e0132fd609f4a05d1ee6af27035d0168a21b37995d2de6d

See more details on using hashes here.

File details

Details for the file uplevel-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: uplevel-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 2.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for uplevel-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fa1d4146219c624b4e1c106101eae1b2845b641ebc623b0e6541656f11e8b558
MD5 868b8f6f93b9ac8534386f57fd1e8c18
BLAKE2b-256 5e7c0f5e32dfe626dcb058b469a665897890556a58dc84f382a3a2ac25b44de2

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page