different behaviour for user defined exception with attribute args

Visco Shaun visco31 at gmail.com
Tue Sep 29 05:43:03 EDT 2009


Hi all

For an exception defined as below

class OptionError(Exception):
    def __init__(self, args):
        self.args = args
    def __str__(self):
        return repr(self.v)

an iteration is happening when the exception is raised

Meanwhile for almost the same structured exception replacing the
attribute 'args' with say 'value' it is not a probs.

class OptionError(Exception):
    def __init__(self, args):
        self.value = args
    def __str__(self):
        return repr(self.value)

This was frustrating because for a st. OptionError('Error') for
exception 1 output will be

OptionError: ('E', 'r', 'r', 'o', 'r') 

Meanwhile for exception 2 output will be 

OptionError: 'Error'

which is desired..Why this behaviour?

Regards
Visco




More information about the Python-list mailing list