[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 testResult == TestOutcomes.FAILED : > testResultAsString = "Failed" > else: > testResultAsString = "Aborted" > > 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?
Why don't use the simple approach like this? TEST_PASSED = "Passed" TEST_FAILED = "Failed" TEST_ABORTED = "Aborted" In Python, no one forces you to put everything in classes. If you are determined to use the class approach, use the __str__ method. It's called when you do str(instance). Regards, Björn -- BOFH excuse #122: because Bill Gates is a Jehovah's witness and so nothing can work on St. Swithin's day. -- http://mail.python.org/mailman/listinfo/python-list