Skip to main content

create a temporary environment to run some code

Project description

TmpVar

TmpVar is used to change the variables environement temprorarily to run some codes and restore the previous environment.

Example

    import TmpVar
    
    a = 3
    b = 6
    c = 9
    class TestClass:
        def __init__(self, a, b, c) -> None:
            self.a = a
            self.b = b
            self.c = c
    d = TestClass(a, b ,c)
    print(a, b, c, 
          d.a, d.b, d.c)
    with TmpVar({'d.a':3354}, a=453):
        print('—————— temporal environment:——————')
        print(a, b, c, 
            d.a, d.b, d.c)
    print('—————— raw environment:——————')
    print(a, b, c, 
          d.a, d.b, d.c)

    # 3 6 9 3 6 9
    # —————— temporal environment:——————
    # 453 6 9 3354 6 9
    # —————— raw environment:——————
    # 3 6 9 3 6 9

Usage

For single variable, you can simpily run it with:

with TempEnv(varname1=value1, varname2=value2,...):
    run some code
    ...

For attribute of variables, you can use:

with TempEnv('varname1.attribute1=value1', 'varname2.attribute2=value2',...):
    run some code
    ...

For some items in list or dict, I didn't figure out how to access them in proper way.

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

TmpVar-0.0.1.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

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

TmpVar-0.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file TmpVar-0.0.1.tar.gz.

File metadata

  • Download URL: TmpVar-0.0.1.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for TmpVar-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4f77a026d41ac5f5dafe236c31e492ed73cc767524afca272ae2af990a91c1d8
MD5 2dcd18f469d280a5418a0e1ddeb2b83e
BLAKE2b-256 e39a02e7907d725ad7762598a701f003e087eb8c713b504c26c30f2093cdbe0c

See more details on using hashes here.

File details

Details for the file TmpVar-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: TmpVar-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for TmpVar-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 27902264619804603448d2715c93ca7f9660491f69793e13beb408f573a33c0c
MD5 226583d1d4e4ea07516013e80c5096ae
BLAKE2b-256 854f3ef3974c33998a8dc02e0024dfdeb0070ae44b65f3602bbcd6b3725945eb

See more details on using hashes here.

Supported by

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