我试图在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('没有xlsx数据文件是FO.。。‘,StackLevel=2)