Reputation: 155
I'm trying to create a custom warning message in a Python script:
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. ')
The problem is that during execution of the script, if I trigger this message the output looks like:
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. ')
I don't want this warnings.warn...
on the last row to appear and to show the raw structure of the message. Any way to hide it?
Upvotes: 2
Views: 523
Reputation: 351
use this: warnings.warn('No xlsx data files are fo...' , stacklevel=2)
Upvotes: 3