Spacename
An alternative to dictionaries, built on the argparse Namespace class.
Table of contents
Installation
Currently, you are only able to install spacename using pip or similar package managers1. 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)
Output:
True
-
Supported package managers include, but are not limited to, pip, poetry, and any other package manager that supports the PyPI repository. ↩
Release files for spacename 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spacename-1.0.1.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spacename-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.3 kB
Release files / spacename-1.0.1.tar.gz
| Download URL | spacename-1.0.1.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a7c61fd63fd8f55008f9e350bff05274556bce0a9164f0a64c8d14c86004c36
|
|
BLAKE2b-256 checksum How to use checksums |
a27b0fff1e3a430a4a146f4781680d381de4ef3eda6a29f5b82f6b344e563336
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / spacename-1.0.1-py3-none-any.whl
| Download URL | spacename-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a1d1c3c36ac71871bb815eec0d57f60b13e4258a05d44d0624f0f01da844b89
|
|
BLAKE2b-256 checksum How to use checksums |
d51532c76690588a8147a1cb523408998f03803f76e34278cb7da110575dd0c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|