473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

enum 0.2: Enumerations in Python

Howdy all,

I've uploaded enum 0.2 to the Cheeseshop.

The main change is that enumeration values now export their enumtype,
index, and key (the things that define each value) as attributes.
Thanks to Bengt for making a convincing case in favour of this.

So now it's easier to ask an enumeration value about itself:
from enum import Enum
Weekdays = Enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') print [str(v) for v in Weekdays] ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
today = Weekdays.tue
print str(today) tue print repr(today) EnumValue(<enum.Enum object at 0xb7d1ceec>, 2, 'tue')
print today.enumtype <enum.Enum object at 0xb7d1ceec> print today.index 2 print today.key

tue

--
\ "I spilled spot remover on my dog. Now he's gone." -- Steven |
`\ Wright |
_o__) |
Ben Finney
Nov 22 '05 #1
0 860

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Steven T. Hatton | last post by:
Any opinions or comments on the following? I don't say it below, but I came out on the side of using enumerations over static constants. /* I'm trying to figure out the pros and cons of using...
21
by: Bilgehan.Balban | last post by:
Hi, I have two different enum definitions with members of same name. The compiler complains about duplicate definitions. Is this expected behaviour? Can't I have same-named fields in...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
0
by: Ben Finney | last post by:
Howdy all, I've uploaded enum 0.2 to the Cheeseshop. The main change is that enumeration values now export their enumtype, index, and key (the things that define each value) as attributes....
0
by: Ben Finney | last post by:
Howdy all, I've uploaded enum 0.3 to the Cheeseshop. <URL:http://cheeseshop.python.org/pypi/enum/> Enumerations are now sequences, iterable (as before) *and* indexable:: >>> from enum...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
3
by: MathStuf | last post by:
I am creating a program that uses a lot of enumerations and associated arrays of strings that look like this: enum Enum1 { E1_NONE = -1, E1_A = 0, E1_B = 1, E1_END = 2 }
4
by: Jure Bogataj | last post by:
Hi all! I have two enumerations: public enum MyEnum1 and public enum MyEnum2 I want to create function that accepts parameter as member of either enumeration. Is this at all possible?
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.