import sys sys.stderr.write('Warning, log file not found starting a new one\n') #The most direct way to terminate a script is to use "sys.exit()".