Replacement for e.message() in python 2.6

Chris Prinos chrisprinos at gmail.com
Fri Feb 19 19:23:43 CET 2010


On Feb 17, 4:58 am, Nandakumar Chandrasekhar <navanitach... at gmail.com>
wrote:
> Dear Folks,
>
> In previous versions of Python I used to use e.message() to print out
> the error message of an exception like so:
>
> try:
>         result = x / y
> except ZeroDivisionError, e:
>         print e.message()
>
> Unfortunately in Python 2.6 the message method is deprecated.
>
> Is there any replacement for the message method in Python 2.6 or is
> there any best practice that should be used in Python from now on?
>
> Thank you.
>
> Yours sincerely,
> Nanda

try:
        result = x / y
except ZeroDivisionError as e:
        print e

Note different syntax using "except ... as ..."

e.message is deprecated here, but e.args[0] contains the same thing.

see http://docs.python.org/dev/3.0/whatsnew/2.6.html#pep-3110
and http://www.python.org/dev/peps/pep-3110/

chris



More information about the Python-list mailing list