On Wed, Dec 30, 2009 at 8:39 AM, spir <denis.s...@free.fr> wrote: > Lie Ryan dixit: > >> class Error(Exception): >> def __init__(self, value): >> self.value = value >> def printer(self, value): >> print self.value > > You can also use __str__ instead of printer. This will give a standard output > form for your error automatically used by print and also, for exceptions, > when python writes it to stderr: you don't need to catch the error to write > it yourself. > > def __str_(self, value): > print self.value
Should be def __str__(self): return self.value i.e. __str__() takes just one argument (self) and returns (rather than prints) a string. Kent _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor