<br><br><div class="gmail_quote">On 28 July 2011 13:17, Ezio Melotti <span dir="ltr"><<a href="mailto:ezio.melotti@gmail.com">ezio.melotti@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<div class="im"><br>
<br>
On 28/07/2011 4.12, Nick Coghlan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Thu, Jul 28, 2011 at 10:56 AM, Barry Warsaw<<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>>  wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Again, looking at how I've used them extensively over the last several years,<br>
I would much rather write<br>
<br>
    class Colors(Enum):<br>
        red = 1<br>
        green = 2<br>
        blue = 3<br>
<br>
than<br>
<br>
    red = NamedValue('red', 1)<br>
    green = NamedValue('green', 2)<br>
    blue = NamedValue('blue', 3)<br>
<br>
To me, the duplication is jarring and error prone.<br>
</blockquote>
Yeah, I'd actually be inclined to define such values programmatically<br>
rather than writing them out manually like that:<br>
<br>
_named_colours = dict(<br>
   red=0xFF0000,<br>
   green=0x00FF00,<br>
   blue=0x0000FF,<br>
)<br>
globals().update((k, namedvalue(k, v)) for k, v in _named_colours)<br>
</blockquote>
<br></div>
A method like Colors.make_global([namespace]<u></u>) could be added to do the same thing.<div class="im"><br></div></blockquote><div><br>Colors.make_global(__name__)<br><br>Michael<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
(where namedvalue is the value based factory function I mentioned in<br>
the recipe post)<br>
<br>
However, my contention is that the fundamentally interesting operation<br>
is associating names with values (as your EnumValue class does). Enums<br>
and their ilk are then just syntactic sugar for defining groups of<br>
such values without needing to repeat yourself.<br>
<br>
Cheers,<br>
Nick.<br>
<br>
</blockquote>
<br></div>
Best Regards,<br><font color="#888888">
Ezio Melotti</font><div><div></div><div class="h5"><br>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><pre cols="72"><a href="http://www.voidspace.org.uk/" target="_blank">http://www.voidspace.org.uk/</a><br><br>May you do good and not evil<br>May you find forgiveness for yourself and forgive others<br>
May you share freely, never taking more than you give.<br>-- the sqlite blessing <a href="http://www.sqlite.org/different.html" target="_blank">http://www.sqlite.org/different.html</a></pre>
<br>