From bc0d1aec669d34e142900e562b07dec0696f0160 Mon Sep 17 00:00:00 2001 From: Constantin Date: Mon, 16 Sep 2013 00:47:58 +0200 Subject: [PATCH 1/1] 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 --- tuerd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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: -- 2.30.2