473,395 Members | 1,558 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,395 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 794

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...
1
by: mikron30 | last post by:
Hi, Is it legal to create two enums with the same value? typedef enum { a, b=a, c } save_value_enum;
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.