AutoStrEnum
This project defines an extended Enum class.
It can automatically assign the value to your Enum member, and the value is just the same as the member name!
And when you print it, you won't see the Enum name in front of the class member.
Install
pip install AutoStrEnum
Demo
import json
import pickle
from enum import auto
from AutoStrEnum import AutoStrEnum, AutoJsonEncoder
class Fruit(AutoStrEnum):
BANANA = auto()
WATERMELON = auto()
DURIAN = auto()
KIWI = auto()
class MagicFruit(AutoStrEnum):
BANANA = auto()
WATERMELON = auto()
DURIAN = auto()
if __name__ == '__main__':
print(Fruit, MagicFruit)
print(Fruit.BANANA, Fruit.WATERMELON, Fruit.DURIAN)
print('should be True:', Fruit.BANANA in Fruit)
print('should be True:', Fruit.BANANA is Fruit.BANANA)
print('should be True:', Fruit.BANANA == Fruit.BANANA)
print('should be True:', isinstance(Fruit.BANANA, Fruit))
print('should be False:', isinstance(Fruit.BANANA, str))
print('should be False:', isinstance(Fruit.BANANA, MagicFruit))
print('should be False:', isinstance(False, Fruit))
# We also can use as dict key!
test_dict = {
Fruit: {
Fruit.BANANA: 2,
Fruit.DURIAN: 10,
Fruit.WATERMELON: 0,
'Love': Fruit.KIWI
}}
print(test_dict)
# json dumps is also fine!
print('json dumps', json.dumps(test_dict, indent=4, cls=AutoJsonEncoder))
$ python demo.py
Fruit MagicFruit
BANANA WATERMELON DURIAN
should be True: True
should be True: True
should be True: True
should be True: True
should be False: False
should be False: False
should be False: False
{Fruit: {BANANA: 2, DURIAN: 10, WATERMELON: 0, 'Love': KIWI}}
json dumps {
"Fruit": {
"Love": "KIWI",
"BANANA": 2,
"DURIAN": 10,
"WATERMELON": 0
}
}
Metadata
Release files for AutoStrEnum 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| AutoStrEnum-0.0.10.tar.gz | 3.5 kB | Without provenance | Details for AutoStrEnum-0.0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| AutoStrEnum-0.0.10-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for AutoStrEnum-0.0.10-py2.py3-none-any.whl |
Total release size: 7.4 kB
Release files / AutoStrEnum-0.0.10.tar.gz
| Download URL | AutoStrEnum-0.0.10.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4f0df05562c9da78a23989c3a772f8c985edd912940b90a323a7928f707b847
|
|
BLAKE2b-256 checksum How to use checksums |
edd4e6d63d1af0e9e52b2579736c2b305e0d4022ad0c0d5219641589573a5555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / AutoStrEnum-0.0.10-py2.py3-none-any.whl
| Download URL | AutoStrEnum-0.0.10-py2.py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
06f586d7858b82ad9bfb9e4ea81619ba523210de3ef73f4120d5ac93a8fa9d0d
|
|
BLAKE2b-256 checksum How to use checksums |
5d907e72316da1485832e0c3c9a804f29e7f954b33b8739c5bcac707e01c9c68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for AutoStrEnum 0.0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.