Comments (2)
Just trying to maintain compatibility where convenient. For enum could use https://pypi.python.org/pypi/enum34/ for py2 (providing it doesn't cause problems)
from essp.
After some thinking I would advise to use the aenum
package which is written by the same guy as the stdlib.enum
and enum34
packages. It offers some advanced features and should solve all of the issues, including py2/py3 compatibility.
Here is a sample definition which suits your use case:
from aenum import IntEnum
class Status(IntEnum):
_init_ = 'value', 'debug_message'
OK = 1, "debug message ok"
FAIL = 2, "debug message fail"
The _init_
takes a sequence of attributes to set on each Enum
item. Then you just pass the actual values to each item.
Note that the first attribute passed to
_init_
must bevalue
.
I used IntEnum
as the parent class in the example as this makes the enum a subclass of int
as well but you can just use Enum
if you prefer it.
In the end you should be able to use it like this with py2/py3:
assert Status.OK == Status(1)
assert Status.OK.name == 'OK'
assert Status.OK.value == 1
assert Status.OK.debug_message == "debug message ok"
from essp.
Related Issues (19)
- Refactor `set_route_...` and other action methods
- TypeError: unsupported type for timedelta seconds component: NoneType HOT 4
- libessp.so: undefined symbol: Status HOT 3
- RANDOM.C and use of asm ("RDTSC" : "=A" (result)) FAILS on ARM HOT 4
- essp not working HOT 12
- NV11 First Run HOT 1
- .
- .
- Remove dead code HOT 1
- Can not find unit Smart Hopper on Ubuntu HOT 1
- get_last_event() don't work? HOT 6
- Scenario of disabling and then enabling validator doesn't seem to work
- Segmentation fault HOT 1
- Take the banknote values from NV10 acceptor
- Use an actions queue instead of a string HOT 2
- Remove repetitive return statement
- Comply with PEP8
- Can not use this Library in Windows HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from essp.