What about that?<br>
<br>
SomeNumbers = enum('0', '1', '2', '3', '4', '5', '6', '7')<br>
<br>
or<br>
<br>
Rooms = enum('1bed', '2beds', 'moreThan2beds')<br>
<br>
or even<br>
<br>
Comments = enum('#', ';', '//')<br>
<br>
<br>
Cyril<br><br><div><span class="gmail_quote">On 28 Feb 2006 03:14:25 -0800, <b class="gmail_sendername">Carl Banks</b> <<a href="mailto:invalidemail@aerojockey.com">invalidemail@aerojockey.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Stefan Rank wrote:<br>> on 28.02.2006 07:50 Carl Banks said the following:<br>> > Ben Finney wrote:<br>> >> This PEP specifies an enumeration data type for Python.<br>> ><br>> [snip]<br>> >
<br>> > Here's why I think it's not too useful to begin with: the benefits of<br>> > the enum you describe here are pretty weak.<br>><br>> I need to disagree heavily here :)<br><br>"the benefits of the enum you describe here [beyond my example which I
<br>claimed enum was only a minor improvement over] are pretty weak."<br><br><br>> > It's a pretty weak case to have a dedicated builtin to prevent<br>> > duplicates in something that changes maybe once a month, as enums tend
<br>> > to change rather slowly.  (At least, that's the way enums in other<br>> > languages are used, and the design you present here seems to suggest<br>> > you intend to use them that way as well.)  And frankly, a unit test or
<br>> > assertion could check this.<br>> [snip]<br>><br>> I don't understand what you mean by 'change rather slowly'?<br><br>Construct data structure on-the-fly from an XML file edited by multiple<br>people every day  = changes rather quickly
<br><br>Construct data structure from a Python file that was last edited a year<br>and a half ago = changes rather slowly<br><br>Typically, enums fall into the latter category.  You set the enum<br>values, and then pretty much leave them alone, adding new values only
<br>occasionally.  (Come on, how often do the days of the week change?)<br>All I was saying is, changes to the enum values are infrequent enough<br>that having a special type just to make sure there are no duplicates is<br>
a waste.  The only justification for a built-in enum is the other stuff<br>you mentioned.<br><br><br>> One thing that is probably missing to allow this, is a enum-set-creation<br>> with the | operator::<br>><br>>    Weekdays = enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
<br>>    daysihate = Weekdays.mon | Weekdays.thu<br>><br>> (and this discussion needs to move to python-dev ?)<br><br>What's wrong with set((Weekdays.mon,Weekdays.thu))?  Explicit is better<br>than implicit.<br><br>
<br>> As for the metaclass versions: For myself, the above version feels more<br>> natural and straightforward (in the same way as the PEP author describes<br>> it), though I understand the subclassing ideas.<br>
><br>> But are there use cases for subclassing, that aren't better served with<br>> a new enum or something homegrown?<br>> Can C++/Pascal/Java enums be subclassed?<br><br>In C++, enum is a type but not a class.  Same thing with Ada.  Java
<br>didn't have enums last time I checked.  Don't know about Pascal.  I<br>didn't care too much about subclassing; I just thought different enum<br>constant that couldn't (or, rather, oughtn't) be compared probably<br>should be instances of a separate class.  It doesn't matter much,
<br>though.<br><br>Should something like this work:<br><br>day = Weekdays.mon<br>isinstance(day,Weekdays)<br><br>?<br><br><br>Carl Banks<br><br>--<br><a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a><br></blockquote></div><br>