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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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