Skip to main content

An alternative to dictionaries, built on the argparse Namespace class.

Project description

Spacename

An alternative to dictionaries, built on the argparse Namespace class.

Table of contents

Back to Top

Table of contents

Installation

Usage

Installation

Currently, you are only able to install spacename using pip or similar package managers[^1]. However, this is set to change in the near future.

Using pip

To install this package using pip, simply run the following command:

*Nix

pip3 install spacename

Windows

pip install spacename

Usage

Creating a Namespace

from spacename import Namespace

ns = Namespace(key="val")
print(ns.key)

Output:

"val"

Adding/modifying keys and values to the Namespace

from spacename import Namespace

ns = Namespace(spam="fizz", bacon="buzz")
ns.spam = "foo" # Changing existing value
ns.eggs = "bar" # Creating a key-value pair
del ns.bacon # Deleting a key-value pair

print(ns)

Output:

Namespace(spam="foo", eggs="bar")

Converting to dict

from spacename import Namespace

ns = Namespace(spam="foo", eggs="bar", bacon="baz")

print(dict(ns))

# OR

print(ns.to_dict())

Output:

{'spam':'foo', 'eggs':'bar', 'bacon': 'baz'}

Converting to list

from spacename import Namespace

ns = Namespace(spam="foo", eggs="bar", bacon="baz")

print(list(ns))

Output:

[('spam', 'foo'), ('eggs', 'bar'), ('bacon', 'baz')]

Iterating through a Namespace

from spacename import Namespace

ns = Namespace(spam="foo", eggs="bar", bacon="baz")

for k, v in ns:
	print(f"{k}=\"{v}\"")

Output:

spam="foo"
eggs="bar"
bacon="baz"

Comparing Namespaces with other Namespaces

from spacename import Namespace

ns1 = Namespace(spam="foo", eggs="bar", bacon="baz")
ns2 = Namespace(foo="spam", bar="eggs", baz="bacon")

print(ns1 == ns2)

Output:

False

Checking that a Namespace contains a key

from spacename import Namespace

ns = Namespace(spam="foo", eggs="bar", bacon="baz")

print("spam" in ns)

[^1]: Supported package managers include, but are not limited to, pip, poetry, and any other package manager that supports the PyPI repository.

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

spacename-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

spacename-1.0.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file spacename-1.0.0.tar.gz.

File metadata

  • Download URL: spacename-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for spacename-1.0.0.tar.gz
Algorithm Hash digest
SHA256 61cefd8a808763e40d92784dfb0c90b3516e3d7a58ef434c42cb8c858fb7f060
MD5 46834804353e0871894e0db8684e8c0e
BLAKE2b-256 a78c821aec22c6c6193704694915bd57b0d20477395404c5dde77ecbcb2fc948

See more details on using hashes here.

Provenance

File details

Details for the file spacename-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: spacename-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for spacename-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebba7669fe9ac67f43b3d645e160f1a40bc9baaec45923941454b18cd46a2ed4
MD5 eac7b9b60eb90269c122d34661608446
BLAKE2b-256 9310a7c9a35bdb013d13abca64905e98d6fdc9346c5b96ec1dda38b16bd17968

See more details on using hashes here.

Provenance

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