Python 警告 - 在自定义警告消息末尾删除原始警告输出的任何方式
Python warnings - any way to remove the raw warning output at the end of a custom warning message
我正在尝试在 Python 脚本中创建自定义警告消息:
allfiles = glob.glob(folderpath + "\*.xlsx")
if not allfiles:
warnings.warn('No xlsx data files are found in the folder "'+folderpath+ '"!\n Please note that currently the program could process only this data format. ')
问题是在脚本执行期间,如果我触发此消息,输出如下所示:
UserWarning: No xlsx data files are found in the folder "C:\Users\Savina\Desktop\project\"!
Please note that currently the program could process only this data format.
warnings.warn('No xlsx data files are found in the folder "'+filepath+ '"!\n Please note that currently the program could process only this data format. ')
我不希望最后一行的 warnings.warn...
出现并显示邮件的原始结构。有什么方法可以隐藏它吗?
使用这个:warnings.warn('No xlsx data files are fo...' , stacklevel=2)
我正在尝试在 Python 脚本中创建自定义警告消息:
allfiles = glob.glob(folderpath + "\*.xlsx")
if not allfiles:
warnings.warn('No xlsx data files are found in the folder "'+folderpath+ '"!\n Please note that currently the program could process only this data format. ')
问题是在脚本执行期间,如果我触发此消息,输出如下所示:
UserWarning: No xlsx data files are found in the folder "C:\Users\Savina\Desktop\project\"!
Please note that currently the program could process only this data format.
warnings.warn('No xlsx data files are found in the folder "'+filepath+ '"!\n Please note that currently the program could process only this data format. ')
我不希望最后一行的 warnings.warn...
出现并显示邮件的原始结构。有什么方法可以隐藏它吗?
使用这个:warnings.warn('No xlsx data files are fo...' , stacklevel=2)