Comparisons and sorting of a numeric class....

Rustom Mody rustompmody at gmail.com
Fri Jan 23 18:29:59 CET 2015


On Friday, January 23, 2015 at 10:54:06 PM UTC+5:30, Chris Angelico wrote:
> On Sat, Jan 24, 2015 at 4:03 AM, Rustom Mody wrote:
> > The only workaround I have been able to come up with is:
> >
> > class B4(IntEnum):
> >>         F1 = 0
> >>         F2 = ""
> >>         F3 = None
> >>         T  = 1
> >
> > which is not bad; its ridiculous
> 
> It's ridiculous because you declared an IntEnum and then started using
> non-integer values that boolify to the same value (and don't intify).
> If that even works, it's a total hack, and it might stop working in a
> future version... for example, it doesn't seem to work on my Python
> 3.5:
> 
> >>> class B4(IntEnum):
> ...  F1=0
> ...  F2=""
> ...  F3=None
> ...  T=1
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/local/lib/python3.5/enum.py", line 152, in __new__
>     enum_member = __new__(enum_class, *args)
> ValueError: invalid literal for int() with base 10: ''
> 
> Using Enum instead of IntEnum does work, but it's still hardly a
> normal use of an enumeration.
> 
> ChrisA

I mis-cut-n-pasted.
Should have been Enum not IntEnum



More information about the Python-list mailing list