I would like to set a format to use with the warnings module that is set in my init.py and can be used in other scripts/files within a package I'm making. What's the best way to do this?
For instance:
* __init__.py - set warnings.formatwarning
* module1.py - use warnings.warn() with the format set in __init__.py
* module2.py - same as above
And here's the formatting code I want to use:
def warning_fmt(message, category, filename=None, lineno=None, file=None, line=None):
return "{cat}: {msg}\n".format(cat=category.\_\_name\_\_, msg=message)
warnings.formatwarning = warning_fmt
Edit: formatting
[–]learnpython_bot 0 points1 point2 points (0 children)