Thư viện hữu ích của Tuấn Anh.
Project description
Giới thiệu
tattools01 là 1 thư viện dùng để ghi tham số vào ổ cứng
Tinh năng
1. Mục đích chính
Tạo một base class TactParameters để quản lý parameters cho các module khác nhau, lưu trữ vào file YAML chung .
2. Cách hoạt động
Lần chạy đầu tiên (file YAML chưa tồn tại):
- Lấy giá trị default từ code
- Tạo file YAML với các giá trị default
Các lần chạy sau (file YAML đã tồn tại):
- Đọc giá trị từ file YAML
- Giá trị trong file YAML là ưu tiên cao nhất (user có thể sửa trực tiếp)
- Nếu user xóa một key trong file → lấy giá trị default từ code
- Nếu code thêm key mới → bổ sung vào file với giá trị default
- Save lại file để đồng bộ
3. Các kiểu dữ liệu cần hỗ trợ
| Kiểu | Ví dụ | Cách access |
|---|---|---|
| Scalar | self.test1 = "123" |
obj.test1 |
| List | self.myList = [1, 2, 3] |
obj.myList[0] |
| Dict thường | self.myDict = {"key": "value"} |
obj.myDict["key"] |
| Nested class | self.Minio = clsMinio() |
obj.Minio.IP |
4. Quy tắc merge (QUAN TRỌNG)
┌─────────────────────────────────────────────────────────────┐
│ Code default + File YAML = Kết quả cuối │
├─────────────────────────────────────────────────────────────┤
│ có giá trị có giá trị → Dùng FILE │
│ có giá trị không có key → Dùng DEFAULT │
│ không có có giá trị → Dùng FILE │
└─────────────────────────────────────────────────────────────┘
Deep merge cho nested object:
# Code default:
Minio:
IP: "192.168.3.42:9000"
access_key: "admin"
secret_key: "Proton@2025"
# File YAML (user chỉ sửa IP, xóa secret_key):
Minio:
IP: "10.0.0.1:9000"
access_key: "admin"
# Kết quả:
Minio:
IP: "10.0.0.1:9000" ← từ file (user sửa)
access_key: "admin" ← từ file (giữ nguyên)
secret_key: "Proton@2025" ← từ default (user xóa → khôi phục)
5. Giữ nguyên TYPE sau khi load
# Trước khi load:
self.myDict = {"key": "value"} # dict
self.Minio = clsMinio() # nested class
# Sau khi load từ file:
self.myDict["key"] # vẫn access bằng []
self.Minio.IP # vẫn access bằng .
6. Nhiều module dùng chung 1 file
# My_Project_Name.yml
Module 01:
test1: "123"
myDict: {key1: value1}
Module 02:
test1: "456"
test2: "New param"
chatbotAPI:
Minio:
IP: "192.168.3.42:9000"
.
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 Distribution
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 tatools01-3.0.3.tar.gz.
File metadata
- Download URL: tatools01-3.0.3.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaf28a4adda724a88803388eb5682bbf6f696ca170f25a378cc8ee5fcf9a99be
|
|
| MD5 |
eb7e80a847e70204dfd29369fa5dc82f
|
|
| BLAKE2b-256 |
155ccd799216219a8dbefaba23288adad1ac0eedb375c9861d2c5d1ad32113ed
|
File details
Details for the file tatools01-3.0.3-py3-none-any.whl.
File metadata
- Download URL: tatools01-3.0.3-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e726db600d7775a8243016dda5f65dd7ff8ed79e66d102234af9f0c966237d6
|
|
| MD5 |
5313f357c56d795fd23587236ee0feb5
|
|
| BLAKE2b-256 |
6c965f00ad848a7ae864cd9faafe20dc8a116275aa6f0dd35d4b489642e5e912
|