help with warning formatting

Mike Brown mike at skew.org
Thu Feb 6 12:45:34 EST 2003


I'm trying to get the hang of warnings.

% cat t.py
import warnings
warnings.warn('foo')

% python t.py
t.py:2: UserWarning: foo
  warnings.warn('foo')

Is there a way to just issue the warning message itself, or to at least
suppress printing the line where the warning occurred ("
warnings.warn('foo')" in the example)?

See, I want to warn the user of my application that they're doing something
risky or improper, so I just want to emit the 'foo', subject to the usual
determination of whether the warning needs to be printed at all. For my
purposes, the user doesn't need to know where the warning occurred, and they
certainly don't need to see pieces of the call stack.

The way it works now, it seems to be intended to warn the application
programmer that they're doing something risky in the code (?).

Thanks in advance for any advice.






More information about the Python-list mailing list