
请我喝杯咖啡☕
警告是警报消息,它基本上不会引发异常,也不会终止程序。
警告类别如下所示:
| class | disposition |
|---|---|
| warning | this is the base class of all warning category classes. it is a subclass of exception. |
| userwarning | the default category for warn(). |
| deprecationwarning | base category for warnings about deprecated features when those warnings are intended for other python developers (ignored by default, unless triggered by code in __main__). |
| syntaxwarning | base category for warnings about dubious syntactic features. |
| runtimewarning | base category for warnings about dubious runtime features. |
| futurewarning | base category for warnings about deprecated features when those warnings are intended for end users of applications that are written in python. |
| pendingdeprecationwarning | base category for warnings about features that will be deprecated in the future (ignored by default). |
| importwarning | base category for warnings triggered during the process of importing a module (ignored by default). |
| unicodewarning | base category for warnings related to unicode. |
| unicodewarning | base category for warnings related to unicode. |
| byteswarning | base category for warnings related to bytes and bytearray. |
| resourcewarning | base category for warnings related to resource usage (ignored by default). |
warn() 可以手动发出警告,如下所示:
需要就下吧 1、修正了800*600 和1024*768情况下不能正常显示的BUG 2、站内公告在second\update\login.htm 用户名:jamtoday 密 码:123456 修改用户名和密码在second\update\chklogin.asp中
5
立即学习“Python免费学习笔记(深入)”;
*备忘录:
import warnings
warnings.warn(message="This is a warning.")
# UserWarning: This is a warning.
# warnings.warn(message="This is a warning.")
warnings.warn(message="This is a warning.",
category=None,
stacklevel=1,
source=None,
skip_file_prefixes=())
# UserWarning: This is a warning.
# warnings.warn(message="This is a warning.",
warnings.warn(message="This is a warning.",
category=Warning)
# Warning: This is a warning.
# warnings.warn(message="This is a warning.",
warnings.warn(message="This is a warning.",
category=DeprecationWarning)
# DeprecationWarning: This is a warning.
# warnings.warn(message="This is a warning.",
def test1():
warnings.warn(message="Warning 1",
stacklevel=-100)
warnings.warn(message="Warning 2",
stacklevel=0)
warnings.warn(message="Warning 3",
stacklevel=1)
warnings.warn(message="Warning 4",
stacklevel=2)
warnings.warn(message="Warning 5",
stacklevel=3)
warnings.warn(message="Warning 6",
stacklevel=4)
warnings.warn(message="Warning 7",
stacklevel=5)
warnings.warn(message="Warning 8",
stacklevel=100)
def test2():
test1()
def test3():
test2()
test3()
# UserWarning: Warning 1
# warnings.warn(message="Warning 1",
# UserWarning: Warning 2
# warnings.warn(message="Warning 2",
# UserWarning: Warning 3
# warnings.warn(message="Warning 3",
# UserWarning: Warning 4
# test1()
# UserWarning: Warning 5
# test2()
# UserWarning: Warning 6
# test3()
# UserWarning: Warning 7
# exec(code_obj, self.user_global_ns, self.user_ns)
# UserWarning: Warning 8
以上就是Python 中的警告的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号