(XLOFT) X-Library of tools
Project description
XLOFT
(XLOFT) X-Library of tools.
Currently, the collection is represented by three modules of `NamedTuple`, `Humanism` and `Quantum`.
Documentation
Online browsable documentation is available at https://kebasyaty.github.io/xloft/.
Requirements
View the list of requirements.
Installation
uv add xloft
Usage
- NamedTuple
from xloft import NamedTuple
nt = NamedTuple(x=10, y="Hello", _id="507c7f79bcf86cd7994f6c0e")
# or
d = {"x": 10, "y": "Hello", "_id": "507c7f79bcf86cd7994f6c0e"}
nt = NamedTuple(**d)
nt.x # => 10
nt.y # => Hello
nt._id # => 507c7f79bcf86cd7994f6c0e
nt.z # => raise: KeyError
len(nt) # => 3
nt.keys() # => ["x", "y", "_id"]
nt.values() # => [10, "Hello", "507c7f79bcf86cd7994f6c0e"]
nt.has_key("x") # => True
nt.has_key("y") # => True
nt.hsa_key("_id") # => True
nt.has_key("z") # => False
nt.has_value(10) # => True
nt.has_value("Hello") # => True
nt.has_value("507c7f79bcf86cd7994f6c0e") # => True
nt.has_value([1, 2, 3]) # => False
nt.get("x") # => 10
nt.get("y") # => Hello
nt.get("_id") # => 507c7f79bcf86cd7994f6c0e
nt.get("z") # => None
d = nt.to_dict()
d["x"] # => 10
d.get("y") # => Hello
d.get("z") # => None
for key, val in nt.items():
print(f"Key: {key}, Value: {val}")
nt.update("x", 20)
nt.update("y", "Hi")
nt.update("_id", "new_id")
nt.x # => 20
nt.y # => Hi
nt._id # => new_id
nt.update("z", [1, 2, 3]) # => raise: KeyError
nt["x"] # => raise: KeyError
nt["y"] # => raise: KeyError
nt["_id"] # => raise: KeyError
nt["z"] # => raise: KeyError
nt["x"] = 20 # => TypeError
nt["y"] = "Hi" # => TypeError
nt["_id"] = "new_id" # => TypeError
nt["z"] = [1, 2, 3] # => TypeError
nt.x = 20 # => raise: AttributeDoesNotSetValue
nt.y = "Hi" # => raise: AttributeDoesNotSetValue
nt._id = "new_id" # => raise: AttributeDoesNotSetValue
nt.z = [1, 2, 3] # => raise: AttributeDoesNotSetValue
del nt.x # => raise: AttributeCannotBeDelete
del nt.y # => raise: AttributeCannotBeDelete
del nt._id # => raise: AttributeCannotBeDelete
- Humanism
from xloft.humanism import to_human_size
s = to_human_size(200)
print(s) # => 200 bytes
s = to_human_size(1048576)
print(s) # => 1 MB
s = to_human_size(1048575)
print(s) # => 1023.999 KB
- Quantum
from xloft.quantum import LoopMode, QuantumLoop, count_qubits
num = count_qubits()
print(num) # => 16
def quantum(self, item):
return item * item
data = range(10)
qloop = QuantumLoop(quantum, data, mode=LoopMode.PROCESS_POOL)
results = qloop.run()
print(results) # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Changelog
License
This project is licensed under the MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xloft-0.1.21-py3-none-any.whl.
File metadata
- Download URL: xloft-0.1.21-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874a33d76ff58621d0149f2526b99594598053b1cc80ca9c289b7d7c214d2381
|
|
| MD5 |
eacf1a21f4264479e472440ff74cef17
|
|
| BLAKE2b-256 |
1536c3dcb5334cf56d84525b76c3789ca03d04e6645053721d84305f9350626e
|