Enums: making a single enum

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat May 26 04:00:00 EDT 2018


On 2018年5月25日 23:07:47 -0600, Ian Kelly wrote:
> On Fri, May 25, 2018 at 11:00 PM, Chris Angelico <rosuav at gmail.com>
> wrote:
>> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano
>> <steve+comp.lang.python at pearwood.info> wrote:
[...]
>>> Is there a better way of handling a three-state flag like this?
>>>>>>>> Does it need to have a value of 2? If not:
>>>> # Tri-state logic
>> Maybe = object()
>> The enum has a nice __str__ though.

Yes, that's why I wanted to use enum.
Also because apparently Enums are the future and nobody uses object() any 
more :-)
Actually I don't really need all the features of Enums, I might just 
define my own class:
class Maybe:
 def __repr__(self):
 return "Maybe"
Maybe = Maybe()
I wish there was a simpler way to define symbols with identity but no 
state or behaviour...
-- 
Steve


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /