I have a script, main.py
, that runs a few functions from other scripts in the directory. I had the very unoriginal idea to send myself Slack notifications if specific functions ran correctly or failed, i.e. error handling. How would I use an error handling function located in a separate script - call the file slack_notifications.py
- in my main.py
script? This linked question starts to get at the answer, but it doesn't get to the calling the error function from somewhere else.
main.py
script:
import scraper_file
import slack_notifications
# picture scrape variable
scrape_object = 'Barack Obama'
# scraper function called
scraped_image = scraper_file.pic_scrape(scrape_object)
# error handling?
slack_notifications.scrape_status(scrape_object)
I have tried embedding the called scraper function into the scrape_status()
function, like this: scraped_image = (slack_notifications.scrape_status(scraper_file.pic_scrape(scrape_object)))
and a few other ways, but that doesn't really tell you if it ran successfully, right?
slack_notifications.py
script:
testing = "dunderhead"
def scrape_status(x):
# if this function gets a positive return from the scrape function
# if this function gets any error from the scrape function
try:
x
print(x + ' worked!')
except:
print(x + ' failed!')
if __name__ == '__main__':
scrape_status(testing)
Is there a way to do this? I have been going off these instructions, too.