Re: Enum class

2015-10-15 Thread Peter Otten
Joseph L. Casale wrote: > Is it possible to override __contains__ from the meta class in the derived > class with the Enum type? >>> import enum >>> class M(enum.EnumMeta): ... def __contains__(self, value): ... print("checking", value) ... return super().__contains__(value)

Re: Enum class

2015-10-15 Thread Peter Otten
Joseph L. Casale wrote: > import enum > class M(enum.EnumMeta): >>... def __contains__(self, value): >>... print("checking", value) >>... return super().__contains__(value) >>... > class Colors(enum.Enum, metaclass=M): >>... red = 1 >>... green = 2 >>...

Re: Enum class

2015-10-15 Thread Joseph L. Casale
import enum class M(enum.EnumMeta): >... def __contains__(self, value): >... print("checking", value) >... return super().__contains__(value) >... class Colors(enum.Enum, metaclass=M): >... red = 1 >... green = 2 >... blue = 3 >... Colors.red in

RE: Enum class

2015-10-15 Thread Joseph L. Casale
> Like that? > > >>> class M2(enum.EnumMeta): >... def __contains__(self, value): >... print(value, "? never", sep="") >... return False >... > >>> Colors.__class__ > > >>> Colors.red in Colors > checking Colors.red > True > >>> Colors.__class__ = M2 > >>> Colors.red in

Re: Enum class with ToString functionality

2007-09-12 Thread Neil Cerutti
On 2007-09-11, Steven D'Aprano [EMAIL PROTECTED] wrote: Perhaps Ben should have followed the usual practice of commercial, closed- source software developers and started counting his version numbers at one instead of zero, miss a few releases, use randomly large increments occasionally, and

Re: Enum class with ToString functionality

2007-09-11 Thread J. Cliff Dyer
Zara wrote: On Mon, 10 Sep 2007 02:28:57 -0700, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult ==

Re: Enum class with ToString functionality

2007-09-11 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED: testResultAsString = Passed

Re: Enum class with ToString functionality

2007-09-11 Thread Steven D'Aprano
On Mon, 10 Sep 2007 18:03:11 -0700, TheFlyingDutchman wrote: I'd like to know if the Cheeseshop package 'enum' is useful to you. Any constructive feedback would be appreciated. URL:http://cheeseshop.python.org/pypi/enum/ Looking at the documentation it looks excellent. But I don't

Re: Enum class with ToString functionality

2007-09-10 Thread Duncan Booth
[EMAIL PROTECTED] wrote: But it would be much nicer if I had a function to covert to string as part of the TestOutcomes class. How would I implement this? Perhaps: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486 -- http://mail.python.org/mailman/listinfo/python-list

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED:

Re: Enum class with ToString functionality

2007-09-10 Thread aine_canby
On 10 Sep, 13:35, TheFlyingDutchman [EMAIL PROTECTED] wrote: On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED

Re: Enum class with ToString functionality

2007-09-10 Thread David
On 9/10/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED:

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED:

Re: Enum class with ToString functionality

2007-09-10 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED: testResultAsString = Passed elif

Re: Enum class with ToString functionality

2007-09-10 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit : On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED:

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 8, 9:52 am, Bruno Desthuilliers [EMAIL PROTECTED] wrote: TheFlyingDutchman a écrit : On Sep 10, 2:28 am, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult =

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
[EMAIL PROTECTED] writes: But it would be much nicer if I had a function to covert to string as part of the TestOutcomes class. How would I implement this? Others have given ad hoc implementations that may do what you want. I'd like to know if the Cheeseshop package 'enum' is useful to you.

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
I'd like to know if the Cheeseshop package 'enum' is useful to you. Any constructive feedback would be appreciated. URL:http://cheeseshop.python.org/pypi/enum/ Looking at the documentation it looks excellent. But I don't understand the 0.4.2 version number, particularly when you refer

Re: Enum class with ToString functionality

2007-09-10 Thread Bruno Desthuilliers
TheFlyingDutchman a écrit : On Sep 8, 9:52 am, Bruno Desthuilliers [EMAIL PROTECTED] wrote: TheFlyingDutchman a écrit : (snip) class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 def ToString(outcome): if outcome == TestOutcomes.PASSED: return Passed

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
TheFlyingDutchman [EMAIL PROTECTED] writes: URL:http://cheeseshop.python.org/pypi/enum/ (Please preserve attribution lines so it's clear who wrote what.) Looking at the documentation it looks excellent. But I don't understand the 0.4.2 version number, Note the tag that says the

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 7:12 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: URL:http://cheeseshop.python.org/pypi/enum/ (Please preserve attribution lines so it's clear who wrote what.) Looking at the documentation it looks excellent. But I don't understand

Re: Enum class with ToString functionality

2007-09-10 Thread J. Cliff Dyer
TheFlyingDutchman wrote: On Sep 10, 7:12 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: URL:http://cheeseshop.python.org/pypi/enum/ (Please preserve attribution lines so it's clear who wrote what.) Looking at the documentation it looks excellent. But

Re: Enum class with ToString functionality

2007-09-10 Thread Ben Finney
TheFlyingDutchman [EMAIL PROTECTED] writes: On Sep 10, 7:12 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: Looking at the documentation it looks excellent. But I don't understand the 0.4.2 version number, Note the tag that says the Development

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 8:02 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: On Sep 10, 7:12 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: Looking at the documentation it looks excellent. But I don't understand the 0.4.2

Re: Enum class with ToString functionality

2007-09-10 Thread TheFlyingDutchman
On Sep 10, 7:55 pm, J. Cliff Dyer [EMAIL PROTECTED] wrote: TheFlyingDutchman wrote: On Sep 10, 7:12 pm, Ben Finney [EMAIL PROTECTED] wrote: TheFlyingDutchman [EMAIL PROTECTED] writes: URL:http://cheeseshop.python.org/pypi/enum/ (Please preserve attribution lines so it's clear who wrote

Re: Enum class with ToString functionality

2007-09-10 Thread Zara
On Mon, 10 Sep 2007 02:28:57 -0700, [EMAIL PROTECTED] wrote: Hi, I have the following class - class TestOutcomes: PASSED = 0 FAILED = 1 ABORTED = 2 plus the following code - testResult = TestOutcomes.PASSED testResultAsString if testResult == TestOutcomes.PASSED: