I want to check both whether a file exists and, if it does, if it is empty.
If the file doesn't exist, I want to exit the program with an error message.
If the file is empty I want to exit with a different error message.
Otherwise I want to continue.
I've been reading about using Try: Except: but I'm not sure how to structure the code 'Pythonically' to achieve what I'm after?
Thank you for all your responses, I went with the following code:
try:
if os.stat(URLFilePath + URLFile).st_size > 0:
print "Processing..."
else:
print "Empty URL file ... exiting"
sys.exit()
except OSError:
print "URL file missing ... exiting"
sys.exit()