how to suppress the "source code echo" output by warnings.warn("x")?

funkyj funkyj at gmail.com
Fri May 19 23:03:57 CEST 2006


Peter Otten wrote:
> funkyj wrote:
>
> > I've been googling around trying to find the answer to this question
> > but all I've managed to turn up is a 2 year old post of someone else
> > asking the same question (no answer though).

> How about monkey-patching?
>
> import warnings
>
> def formatwarning(message, category, filename, lineno):
>     return  "%s:%s: %s: %s\n" % (filename, lineno,
>         category.__name__, message)
>
> warnings.formatwarning = formatwarning
> 
> warnings.warn("so what")

Thanks, that did the trick!




More information about the Python-list mailing list