Tutorial - section 8.5 -- User Defined Execptions?

user at domain.invalid user at domain.invalid
Wed Apr 16 06:27:19 EDT 2003


 From the python documentation tutorial, section 8.5
+++++++++++++++++++++++++++++++++++=
 >>> class MyError:
...     def __init__(self, value):
...         self.value = value
...     def __str__(self):
...         return `self.value`
...
 >>> try:
...     raise MyError(2*2)
... except MyError, e:
...     print 'My exception occurred, value:', e.value
...
My exception occurred, value: 4
 >>> raise MyError, 1
Traceback (innermost last):
   File "<stdin>", line 1
__main__.MyError: 1

+++++++++++++++++++++++++++++++++++=

What do the back ticks in method "__str__" mean?





More information about the Python-list mailing list