Tutorial - section 8.5 -- User Defined Execptions?
Colin J. Williams
cjw at sympatico.ca
Thu Apr 17 12:40:35 EDT 2003
user at domain.invalid wrote:
> 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?
The back ticks, as in `self.value`, are equivalent to repr(`self.value`).
ie. it provides the ``official'' string representation of self.value.
Colin W.
More information about the Python-list
mailing list