Python will by default prints warning messages to sys.stderr.
warning_example.pyimport warnings
def print_warning():
print("Hello there!")
warnings.warn("This is a warning message!", Warning)
print_warning()
Run the python file:
% python3 warning_example.py
Warning:
If you wish to not display this warning message when you execute the Python script, all you need to do is pass in the option -Wignore
Example:python3 -Wignore warning_example.py
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!