From: Constantin Date: Sun, 15 Sep 2013 22:47:58 +0000 (+0200) Subject: my senf to ralfs senf to tuerd X-Git-Url: https://git.ralfj.de/saartuer.git/commitdiff_plain/bc0d1aec669d34e142900e562b07dec0696f0160?ds=sidebyside;hp=-c my senf to ralfs senf to tuerd as suggested in http://stackoverflow.com/questions/10840533/most-pythonic-way-to-delete-a-file-which-may-not-exist --- bc0d1aec669d34e142900e562b07dec0696f0160 diff --git a/tuerd b/tuerd index 00b2420..5884d13 100755 --- a/tuerd +++ b/tuerd @@ -1,5 +1,5 @@ #!/usr/bin/python3 -import time, socket, os, stat, atexit +import time, socket, os, stat, atexit, errno from datetime import datetime import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) @@ -25,8 +25,12 @@ def doNothing (conn): # delete a file, don't care if it did not exist in the first place def forcerm(name): - if os.path.exists(name): + try: os.unlink (name) + except OSError as e: + # only ignore error if it was "file didn't exist" + if e.errno != errno.ENOENT: + raise # commands: on a pin do a series of timed on/off switches class Pinoutput: