Currently, you are only able to install spacename using pip or similar package managers1. However, this is set to change in the near future.
To install this package using pip, simply run the following command:
pip3 install spacename
pip install spacename
from spacename import Namespace
ns = Namespace(key="val")
print(ns.key)
Output:
val
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")
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'}
from spacename import Namespace
ns = Namespace(spam="foo", eggs="bar", bacon="baz")
print(list(ns))
Output:
[('spam', 'foo'), ('eggs', 'bar'), ('bacon', 'baz')]
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"
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
from spacename import Namespace
ns = Namespace(spam="foo", eggs="bar", bacon="baz")
print("spam" in ns)
Output:
True
Footnotes
-
Supported package managers include, but are not limited to, pip, poetry, and any other package manager that supports the PyPI repository. ↩