File: PKG-INFO

package info (click to toggle)
python-easy-enum 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 88 kB
  • sloc: python: 99; makefile: 4
file content (129 lines) | stat: -rw-r--r-- 5,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Metadata-Version: 1.1
Name: easy-enum
Version: 0.3.0
Summary: User friendly implementation of Enum in Python
Home-page: https://github.com/molejar/pyEnum
Author: Martin Olejar
Author-email: martin.olejar@gmail.com
License: Apache 2.0
Description: pyEnum
        ======
        
        |Build Status| |Coverage Status| |PyPI Status| |Python Version|
        
        User friendly implementation of documented ``Enum`` type for Python
        language.
        
        Installation
        ------------
        
        .. code:: bash
        
                $ pip install easy_enum
        
        To install the latest version from master branch execute in shell
        following commands:
        
        .. code:: bash
        
                $ pip install -U https://github.com/molejar/pyEnum/archive/master.zip
        
        In case of development, install pyEnum from sources:
        
        .. code:: bash
        
                $ git clone https://github.com/molejar/pyEnum.git
                $ cd pyEnum
                $ pip install -U -e .
        
        You may run into a permissions issues running these commands. Here are a
        few options how to fix it:
        
        1. Run with ``sudo`` to install pyEnum and dependencies globally
        2. Specify the ``--user`` option to install locally into your home
           directory (export "~/.local/bin" into PATH variable if haven't).
        3. Run the command in a
           `virtualenv <https://virtualenv.pypa.io/en/latest/>`__ local to a
           specific project working set.
        
        Usage
        -----
        
        Following example is showing how easy you can use this Enum in your
        code:
        
        .. code:: python
        
                from easy_enum import Enum
        
                class TestEnum(Enum):
        
                    # attribute with no description, the name will be 'FIRST_ITEM' and empty string as description
                    FIRST_ITEM  = 1
        
                    # attribute with description
                    SECOND_ITEM = (2, 'Description for second item')
        
                    # attribute with description and custom string name
                    THIRD_ITEM  = (3, 'third', 'Description for third item')
        
                    # attribute with custom string name (the description must be specified as empty string)
                    FOURTH_ITEM = (4, 'fourth', '')
        
        
                # Read attributes value and name
                print(TestEnum.SECOND_ITEM)    # 2
                print(TestEnum['FIRST_ITEM'])  # 1
                print(TestEnum[1])             # 'FIRST_ITEM'
                print(TestEnum[3])             # 'third'
                print(TestEnum['third'])       # 3
        
                # Use get method with default value if want skip exception
                print(TestEnum.get(8))         # None
                print(TestEnum.get('eight'))   # None
                print(TestEnum.get(8, 'eight')) # 'eight'
        
                # Check if exist attribute with specific value
                print(1 in TestEnum)           # True
                print(8 in TestEnum)           # False
        
                # Check if exist attribute with specific name
                print('first' in TestEnum)     # False
                print('third' in TestEnum)     # True
        
                # Get attribute description (as parameter use attribute name or value)
                print(TestEnum.desc(1))        # ''
                print(TestEnum.desc(2))        # 'Description for second item'
                print(TestEnum.desc('third'))  # 'Description for third item'
                
                # Get count of all attributes
                print(len(TestEnum))           # 4
        
                # Get list with all attributes name
                names = [item[0] for item in TestEnum]
                print(names)                   # ['FIRST_ITEM', 'SECOND_ITEM', 'third', 'fourth']
        
                # Get list with all attributes value
                values = [item[1] for item in TestEnum]
                print(values)                  # [1, 2, 3, 4]
        
                # Read all items
                for name, value, desc in TestEnum:
                    print('{} = {} ({})'.format(name, value, desc))
        
        .. |Build Status| image:: https://travis-ci.org/molejar/pyEnum.svg?branch=master
           :target: https://travis-ci.org/molejar/pyEnum
        .. |Coverage Status| image:: https://coveralls.io/repos/github/molejar/pyEnum/badge.svg?branch=master
           :target: https://coveralls.io/github/molejar/pyEnum?branch=master
        .. |PyPI Status| image:: https://img.shields.io/pypi/v/easy-enum.svg
           :target: https://pypi.python.org/pypi/easy-enum
        .. |Python Version| image:: https://img.shields.io/pypi/pyversions/easy-enum.svg
           :target: https://www.python.org
        
Platform: UNKNOWN
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities