# AutoStrEnum
Project description
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
Basic use
from enum import auto
from AutoStrEnum import AutoStrEnum
class Fruit(AutoStrEnum):
BANANA = auto()
WATERMELON = auto()
DURIAN = auto()
class MagicFruit(AutoStrEnum):
BANANA = auto()
WATERMELON = auto()
DURIAN = auto()
if __name__ == '__main__':
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.BANANA: 2,
Fruit.DURIAN: 10,
Fruit.WATERMELON: 0
}
print(test_dict)
$ python demo.py
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
{BANANA: 2, DURIAN: 10, WATERMELON: 0}
You can find all the example at demo.py
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
AutoStrEnum-0.0.3.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for AutoStrEnum-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2000c460691586c46e37c31cf69b69d6c9eed4706f28a6e4e66b4a71f738262b |
|
MD5 | 840a5c7664c4eed01d73da758e38644e |
|
BLAKE2b-256 | ef1fd78822d79a4325fc088492d8fe4c4d161706169e32a5d39dfc0851f75c5f |