Enum class with ToString functionality
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sat Sep 8 14:32:15 EDT 2007
TheFlyingDutchman a écrit :
> On Sep 8, 9:52 am, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
>
>>TheFlyingDutchman a écrit :
(snip)
>>>class TestOutcomes:
>>> PASSED = 0
>>> FAILED = 1
>>> ABORTED = 2
>>
>>> def ToString(outcome):
>>> if outcome == TestOutcomes.PASSED:
>>> return "Passed"
>>> elif outcome == TestOutcomes.FAILED :
>>> return "Failed"
>>> else:
>>> return "Aborted"
>>
>>> ToString = staticmethod(ToString)
>>
(snip)
>>Technically correct, but totally unpythonic.
>
>
> Speaking of unpythonic, I would call
>
> ToString = staticmethod(ToString)
>
> A Perlific syntax.
Nope, just a good ole HOF.
But nowadays, it's usually written this way:
@staticmethod
def some_static_method():
pass
>
>>May I suggest some reading ?http://dirtsimple.org/2004/12/python-is-not-java.html
>
> Well the Foo.Foo complaint is bogus:
>
> from Foo import Foo
>
Yes. And properties are bogus - just use getters and setters.
Seriously, writing Java in Python is definitively on the masochist side.
But if you like pain...
More information about the Python-list
mailing list