我正在尝试在 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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)