Skip to main content

Ultra simple module for creating local scopes in Python

Project description

VarScope Logo

VarScope

Documentation codecov

Ultra simple module for creating local scopes in Python.

Installation

VarScope can be installed with pip:

pip install varscope

Usage

>>> from varscope import scope
>>>
>>> a = 1
>>> with scope():  # Everything defined after will only apply inside the scope
...     a = 2
...     b = 3
...
>>> a
1
>>> b  # Not defined, because outside of scope
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>>
>>> with scope() as s:  # We can choose to keep some variables
...     a = 2
...     b = 3
...     s.keep("b")
...
>>> b
3
>>> with scope("a"):  # We can also move variables inside scope
...     a = 2
...
>>> a  # Not defined, because outside of scope
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>>
>>> d = {}
>>> with scope():  # Scope can mutate object from outside
...     d["a"] = 1
...
>>> d["a"]
1

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

varscope-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

varscope-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file varscope-0.1.1.tar.gz.

File metadata

  • Download URL: varscope-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure

File hashes

Hashes for varscope-0.1.1.tar.gz
Algorithm Hash digest
SHA256 12bb03e38506f45e1952bba03e622cf08835548fd8fd2734e1026c7e0ee3ab9d
MD5 6428275c97c96cddc1bbf39115e3fd93
BLAKE2b-256 598b0610f3f1012addec72d752e22a0e3b8f6222d03d0b9181fce0c573e409f2

See more details on using hashes here.

File details

Details for the file varscope-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: varscope-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1042-azure

File hashes

Hashes for varscope-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e02fea1ec9d030834913aa2805b39d415239a0a899e7d10ba290075d236854d
MD5 d21605aaf2213a7d2adc996b8af1cebe
BLAKE2b-256 36c10a87217f6fd3fb54381e58ae9aa158cad72559a98365e569ce182d3e52d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page