import warnings
warnings.warn("Warning...........Message")

See the python documentation: here

Answer from necromancer on Stack Overflow
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί warnings.html
Warning control β€” Python 3.14.3 documentation
January 29, 2026 - Insert an entry into the list of warnings filter specifications. The entry is inserted at the front by default; if append is true, it is inserted at the end. This checks the types of the arguments, compiles the message and module regular expressions, and inserts them as a tuple in the list ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί warnings-in-python
Warnings in Python - GeeksforGeeks
January 23, 2020 - Traceback (most recent call last): File "main.py", line 8, in warnings.warn('This is a warning message') UserWarning: This is a warning message In the above program, a single entry is added to the warnings filter using warnings.simplefilter('error', UserWarning) in which the action is "error" and category is UserWrning and then the warning is displayed using the warn() method. Comment Β· Article Tags: Article Tags: Python Β· Python-Miscellaneous Β· Python Fundamentals Β· Python Introduction1 min read Β· Input and Output in Python2 min read Β· Python Variables4 min read Β· Python Operators4 min read Β· Python Keywords2 min read Β· Python Data Types8 min read Β·
🌐
Python Module of the Week
pymotw.com β€Ί 2 β€Ί warnings
warnings – Non-fatal alerts - Python Module of the Week
import warnings warnings.filterwarnings('ignore', '.*do not.*',) warnings.warn('Show this message') warnings.warn('Do not show this message') The pattern contains β€œdo not”, but the actual message uses β€œDo not”. The pattern matches because the regular expression is always compiled to look for case insensitive matches. $ python warnings_filterwarnings_message.py warnings_filterwarnings_message.py:14: UserWarning: Show this message warnings.warn('Show this message')
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_module_warnings.asp
Python warnings Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... import warnings warnings.warn('This is a warning message') print('Program continues...') Try it Yourself Β»
🌐
Plain English
python.plainenglish.io β€Ί controlling-warning-messages-in-python-4ca7ed37ca94
Controlling Warning Messages in Python | Python in Plain English
October 27, 2024 - It is used for general-purpose warnings where a specific warning type doesn’t fit. warnings.warn("This is a user warning.", UserWarning) DeprecationWarning: This warning is issued when a feature or function is marked for removal in future versions of Python.
🌐
Python
docs.python.org β€Ί 3.1 β€Ί library β€Ί warnings.html
27.4. warnings β€” Warning control β€” Python v3.1.5 documentation
Insert an entry into the list of warnings filter specifications. The entry is inserted at the front by default; if append is true, it is inserted at the end. This checks the types of the arguments, compiles the message and module regular expressions, and inserts them as a tuple in the list ...
🌐
Wing Python IDE
wingware.com β€Ί doc β€Ί warnings β€Ί warning-types
Warnings Types - Wing Python IDE
Undefined Name warnings are shown when a variable is used without the variable ever being set, or when a function is used without defining the function. This warning usually indicates broken code that should be fixed, and warnings of this type should be disabled only in rare cases.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί python_warnings.htm
Python - Warnings
The UserWarning is the default warning class in Python. If you have any warning that does not fall into any of the other categories, it will be classified as a UserWarning. To specify a UserWarning, use UserWarning as the second argument to the warn() function.
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί exceptions.html
Built-in Exceptions β€” Python 3.14.3 documentation
BaseException β”œβ”€β”€ BaseExceptionGroup β”œβ”€β”€ GeneratorExit β”œβ”€β”€ KeyboardInterrupt β”œβ”€β”€ SystemExit └── Exception β”œβ”€β”€ ArithmeticError β”‚ β”œβ”€β”€ FloatingPointError β”‚ β”œβ”€β”€ OverflowError β”‚ └── ZeroDivisionError β”œβ”€β”€ AssertionError β”œβ”€β”€ AttributeError β”œβ”€β”€ BufferError β”œβ”€β”€ EOFError β”œβ”€β”€ ExceptionGroup [BaseExceptionGroup] β”œβ”€β”€ ImportError β”‚ └── ModuleNotFoundError β”œβ”€β”€ LookupError β”‚ β”œβ”€β”€ IndexError β”‚ └── KeyError β”œβ”€β”€ MemoryError β”œβ”€β”€ NameError β”‚ └── UnboundLocalError β”œβ”€β”€
🌐
Cam
downloads.ccdc.cam.ac.uk β€Ί documentation β€Ί API β€Ί descriptive_docs β€Ί warnings.html
Warnings β€” CSD Python API 3.6.1 documentation
The warnings module in Python provides a way to control how warnings handled within a Python script. It allows developers to emit warning messages to alert users of potential issues or unexpected behavior in their code. It is commonly used when a method is marked for deprecation, but can also be applied to warn about unexpected runtime conditions. The warnings module provides several functions to create warnings, and other functions to control how they are handled or displayed, including: warn(message, warning_type=None, stacklevel=1): Generates a warning message.
🌐
Python
docs.python.org β€Ί 3.14 β€Ί library β€Ί warnings.html
warnings β€” Warning control
Insert an entry into the list of warnings filter specifications. The entry is inserted at the front by default; if append is true, it is inserted at the end. This checks the types of the arguments, compiles the message and module regular expressions, and inserts them as a tuple in the list of warnings filters.
🌐
Python
docs.python.org β€Ί 3.9 β€Ί library β€Ί warnings.html
warnings β€” Warning control β€” Python 3.9.21 documentation
Insert an entry into the list of warnings filter specifications. The entry is inserted at the front by default; if append is true, it is inserted at the end. This checks the types of the arguments, compiles the message and module regular expressions, and inserts them as a tuple in the list ...
🌐
DEV Community
dev.to β€Ί hyperkai β€Ί warning-in-python-415g
Warning in Python - DEV Community
May 14, 2025 - A warning is the alert message which doesn't basically raise an exception and doesn't terminate program. ... The 1st argument is message(Required-Type:str).
🌐
Coderz Column
coderzcolumn.com β€Ί tutorials β€Ί python β€Ί warnings-simple-guide-to-handle-warning-messages-in-python
warnings - Simple Guide to Handle Warning Messages in Python by Sunny Solanki
category - This parameter accepts any of the Warning category (a subclass of Warning) from the list of available warnings with python. If not provided warning of type Warning will be raised.
🌐
Python
docs.python.org β€Ί 2.4 β€Ί lib β€Ί warning-categories.html
3.20.1 Warning Categories
October 18, 2006 - A warning category must always be a subclass of the Warning class.
🌐
Runebook.dev
runebook.dev β€Ί en β€Ί docs β€Ί python β€Ί library β€Ί exceptions β€Ί Warning
The Developer's Guide to Python Built-in Warnings and Alternatives
| Problem Code (The Pitfall) | Alternative (The Fix) | Explanation | | :--- | :--- | :--- | | **Fatal Error Misused as Warning:**<br/>A function gets an invalid type, but instead of raising a `TypeError`, it issues a `UserWarning` and returns `None`. | **Use Exceptions for Errors:**<br/>If the program *cannot* continue with the input, raise an exception. | **Warnings** are for things the user *should* know about but the code can *tolerate* (e.g., using a feature that will be slow). **Exceptions** are for unexpected input or failures that stop the process. | | **Example (Correct use of `UserWar
🌐
Reuven Lerner
lerner.co.il β€Ί home β€Ί blog β€Ί python β€Ί working with warnings in python (or: when is an exception not an exception?)
Working with warnings in Python (Or: When is an exception not an exception?) β€” Reuven Lerner
May 12, 2020 - We don’t have to β€œimport” DeprecationWarning, or any other of the standard warning types, because they’re already imported automatically, into the β€œbuiltins” namespace that’s always available to a Python program. And indeed, there are a number of such warning classes that we can use, including UserWarning (the default), DeprecationWarning (which we used here), SyntaxWarning, and UnicodeWarning.
🌐
O'Reilly
oreilly.com β€Ί library β€Ί view β€Ί python-in-a β€Ί 0596100469 β€Ί ch18s03.html
The warnings Module - Python in a Nutshell, 2nd Edition [Book]
July 14, 2006 - Class Warning subclasses Exception and is the base class for all warnings. You may define your own warning classes; they must subclass Warning, either directly or via one of its other existing subclasses, which are: ... Python supplies no concrete warning objects.
Author Β  Alex Martelli
Published Β  2006
Pages Β  734
🌐
Python Module of the Week
pymotw.com β€Ί 3 β€Ί warnings
warnings β€” Non-fatal Alerts
In this example, the simplefilter() function adds an entry to the internal filter list to tell the warnings module to raise an exception when a UserWarning warning is issued. $ python3 -u warnings_warn_raise.py Before the warning Traceback (most recent call last): File "warnings_warn_raise.py", line 15, in <module> warnings.warn('This is a warning message') UserWarning: This is a warning message